New APIs - Please feedback on rewriting FlowStacks #51
Replies: 8 comments 10 replies
-
Here's an example of rewriting code that uses the current FlowStacks APIs: Current APIenum Screen {
case home
case numberList
case numberDetail(Int)
}
struct AppCoordinator: View {
@State var routes: Routes<Screen> = [.root(.home)]
var body: some View {
Router($routes) { screen, _ in
switch screen {
case .home:
HomeView()
case .numberList:
NumberListView()
case .numberDetail(let number):
NumberDetailView(number: number)
}
}
}
} Proposed APIenum Screen {
case numberList
case numberDetail(Int)
}
struct AppCoordinator: View {
@State var routes: Routes<Screen> = []
var body: some View {
FlowStack(path: $routes) {
HomeView()
.flowDestination(for: Screen.self) { screen in
switch screen {
case .numberList:
NumberListView()
case .numberDetail(let number):
NumberDetailView(number: number)
}
}
}
}
There's no longer a type guarantee that the routes array's screen type matches the destination builder's screen argument, but that's what allows the destination builder to be decoupled from the state management. The root screen is no longer part of the routes array, which might be awkward if your flow required you to swap out the root screen. In those cases, I imagine you would need to either:
|
Beta Was this translation helpful? Give feedback.
-
Great work @johnpatrickmorgan, playing around on the new branch this week. The plan is to add this new api and slowly deprecate the other api? |
Beta Was this translation helpful? Give feedback.
-
Also think an example with a View Model (ObservableObject) would be a good to have in the discussion |
Beta Was this translation helpful? Give feedback.
-
Speaking no the main disadvantage of not being able to start off with the root through the routes array, how do you propose we go about a case where the root view needs a view model to be initialised? |
Beta Was this translation helpful? Give feedback.
-
I like the new api 😊 @johnpatrickmorgan, great work! I don't see a major disadvantage with the missing root navigation, basically thats the same with now having a path or specific flow for tab based navigation. How are subflows/coordinators handled with this approach? I didn't look at the code but I guess that every FlowStack has its FlowPathNavigator or are they shared when a FlowStack is used within another FlowStack? |
Beta Was this translation helpful? Give feedback.
-
@johnpatrickmorgan what's the current state here? I am thinking about using FlowStacks in a new project and I am wondering whether I should use the latest released version or the new-api branch? |
Beta Was this translation helpful? Give feedback.
-
Dear @johnpatrickmorgan , thank you for the great framework. Since this rewriting experiment is over 2 years old, may I ask you if you still consider finishing it? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your patience - this rewrite has been a long time in the works but has now been released as v0.6.0. Please try it out and let me know if you encounter any issues. If you want to migrate an existing project, please see the migration docs. Thank you! |
Beta Was this translation helpful? Give feedback.
-
I've been experimenting with new FlowStacks APIs based on the latest SwiftUI
NavigationStack
APIs. I've rewritten the library with essentially the same entities, but withNavigation
replaced withFlow
:🔀 NavigationStack -> FlowStack
🔀 NavigationLink -> FlowLink
🔀 NavigationPath -> FlowPath
🔀 navigationDestination -> flowDestination
🔀 NavigationPath.CodableRepresentation -> FlowPath.CodableRepresentation
The
FlowStacks
APIs expand theNavigationStack
APIs:FlowNavigator
environment object allows you to easily push, pop, present etc. from deep in your view hierarchy.These APIs offer advantages in decoupling the building of screens from managing flow state, so you can more easily break up navigation across different files or modules, and should feel familiar to SwiftUI users.
The main disadvantage I see is that you can no longer change the root screen via the routes array or path. However, I think that leads to better modelling of app flows.
Here's the branch if you'd like to try it out - I'd like to hear opinions on this rewrite before committing to it as it's a significant change. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions