-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from futuredapp/feature/v1.1.0
Version 1.1.0
- Loading branch information
Showing
20 changed files
with
366 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Sources/FuturedArchitecture/Architecture/ModalCoverModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ModalCoverModel.swift | ||
// | ||
// | ||
// Created by Simon Sestak on 01/08/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct ModalCoverModel<Destination: Hashable & Identifiable>: Identifiable { | ||
let destination: Destination | ||
let style: Style | ||
|
||
public enum Style { | ||
case sheet | ||
#if !os(macOS) | ||
case fullscreenCover | ||
#endif | ||
} | ||
|
||
public var id: Destination.ID { | ||
destination.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Sources/FuturedHelpers/Helpers/CoordinatorSceneFlowProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// CoordinatorSceneFlowProvider.swift | ||
// | ||
// Created by Simon Sestak on 31/07/2024. | ||
// | ||
|
||
import SwiftUI | ||
import FuturedArchitecture | ||
|
||
/** | ||
A protocol providing an interface for reusable scene flow providers. *Reusable scene flow provider* is part of a scene flow, which can be used as a part of more *Flow Coordinators*. The shared section of the flow is taken out of the *Flow Coordinator* and placed into a class conforming to `CoordinatorSceneFlowProvider`. | ||
|
||
Protocol defines necessary (`navigateTo`, `pop`) and optional navigation functions. | ||
Optional functions cater to specific navigational use cases like presenting/dismissing modal screen, and popping to destinations. | ||
|
||
- Warning: The `@EnumIndetable` macro won't function with this scene provider as you need to define a destination with an associated value, which isn't primitive. | ||
|
||
# Notes: # | ||
1. Declare the scene flow provider as a lazy var property in the coordinator. | ||
2. Coordinator destinations should have an enum that encapsulates flow provider destinations. | ||
- `case embededFlow(destination: TemplateSceneFlowProvider.Destination)` | ||
|
||
# Example # | ||
The scene provider is defined in the coordinator as follows: | ||
``` | ||
private lazy var templateSceneFlowProvider: TemplateSceneFlowProvider = { | ||
TemplateSceneFlowProvider( | ||
container: container, | ||
navigateTo: { [weak self] destination in | ||
if destination == .end { | ||
self?.navigate(to: .flowSpecificDestinationAfterEmbededFlow) | ||
} else { | ||
self?.navigate(to: .embeded(destination: destination)) | ||
} | ||
}, pop: { [weak self] in | ||
self?.pop() | ||
} | ||
) | ||
}() | ||
``` | ||
Then scenes can be provided in flow coordinator like: | ||
``` | ||
func scene(for destination: Destination) -> some View { | ||
switch destination { | ||
case let .embededFlow(destination): | ||
templateSceneFlowProvider.scene(for: destination) | ||
case .flowSpecificDestinationAfterEmbededFlow: | ||
SomeComponent(model: ... | ||
} | ||
} | ||
``` | ||
*/ | ||
public protocol CoordinatorSceneFlowProvider { | ||
associatedtype Destination: Hashable & Identifiable | ||
associatedtype DestinationViews: View | ||
|
||
@ViewBuilder | ||
func scene(for destination: Destination) -> DestinationViews | ||
|
||
var navigateTo: (Destination) -> Void { get } | ||
var pop: () -> Void { get } | ||
|
||
var present: ((Destination, ModalCoverModel<Destination>.Style) -> Void)? { get } | ||
var dismissModal: (() -> Void)? { get } | ||
var onModalDismiss: (() -> Void)? { get } | ||
var popTo: ((Destination?) -> Void)? { get } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// SceneDelegate.swift | ||
// | ||
// | ||
// Created by Simon Sestak on 31/07/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
#if !os(macOS) | ||
protocol AppSceneDelegate: AnyObject, UIWindowSceneDelegate, ObservableObject { | ||
var delegate: SceneDelegate? { get set } | ||
} | ||
|
||
protocol SceneDelegate: AnyObject { | ||
func sceneDidEnterBackground(_ scene: UIScene) | ||
func sceneWillEnterForeground(_ scene: UIScene) | ||
} | ||
|
||
private struct SceneDelegateWrapperViewModifier<ApSceneDelegate: AppSceneDelegate>: ViewModifier { | ||
@EnvironmentObject private var sceneDelegate: ApSceneDelegate | ||
|
||
let delegate: SceneDelegate? | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.onAppear { | ||
sceneDelegate.delegate = delegate | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
/// Sets the SceneDelegate for the application. | ||
/// - Parameter appSceneDelegateClass: The call which conforms to the UIWindowSceneDelegate. | ||
/// - Parameter sceneDelegate: The SceneDelegate to set. | ||
/// - Description: | ||
/// In the main app root view call this modifier and pass the SceneDelegate. You need to specify the AppSceneDelegate which conforms to the UIWindowSceneDelegate. | ||
/// This is necessary because the SceneDelegate is accessible in SwiftUI only via EnviromentObject. | ||
func set<T: AppSceneDelegate>(appSceneDelegateClass: T.Type, sceneDelegate: SceneDelegate) -> some View { | ||
modifier(SceneDelegateWrapperViewModifier<T>(delegate: sceneDelegate)) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.