Replies: 1 comment
-
Thanks so much @morluna for kicking off this discussion. I've also given this a little thought, and have a couple of suggestions. But first, to address your main points:
I like this change to have a single fixed root screen. It does restrict how you can use FlowStacks, but I think it's for the better. E.g. I've seen people hit issues where they try to incorporate two discrete flows within one coordinator (for example, logged out and logged in flows), rather than splitting them between two coordinators and switching between the two. I'd like to hear if anyone disagrees with this direction.
I think the main advantage of SwiftUI's new navigation APIs over FlowStacks is that they allow the handling of screen creation (
This is sadly not compatible with a stack that handles both presentation and navigation. See this discussion for more info. AlternativesPersonally, I've considered two options for how FlowStacks might develop: 1. FlowStacks keeps the API it currently hasFlowStacks has some advantages over the new navigation APIs:
2. FlowStacks evolves to match the new navigation APIsIt would look exactly like the navigation APIs (switching Click to view demo code
import FlowStacks
import SwiftUI
struct ContentView: View {
@State var path = FlowPath()
var body: some View {
FlowStack(path: $path, embedRootInNavigationView: true) {
HomeView()
.flowDestination(for: NumberList.self, destination: { numberList in
NumberListView(numberList: numberList)
})
.flowDestination(for: Int.self, destination: { number in
NumberView(number: number, goBackToRoot: { path.goBackToRoot()) })
})
.flowDestination(for: EmojiVisualisation.self, destination: { visualisation in
EmojiView(visualisation: visualisation)
})
}
}
}
// Screen Views
struct HomeView: View {
var body: some View {
VStack(spacing: 8) {
FlowLink(value: NumberList(range: 0 ..< 100), label: { Text("Pick a number") }, style: .presentSheet(embedInNavigationView: true))
}.navigationTitle("Home")
}
}
struct NumberListView: View {
let numberList: NumberList
var body: some View {
List {
ForEach(numberList.range, id: \.self) { number in
FlowLink("\(number)", value: number, style: .push)
}
}.navigationTitle("List")
}
}
struct NumberView: View {
let number: Int
let goBackToRoot: () -> Void
var body: some View {
VStack(spacing: 8) {
Text("\(number)")
FlowLink(
value: number + 1,
label: { Text("Show next number") },
style: .push
)
FlowLink(
value: EmojiVisualisation(emoji: "🐑", count: number),
label: { Text("Visualise with sheep") },
style: .push
)
Button("Go back to root", action: goBackToRoot)
}.navigationTitle("\(number)")
}
}
struct EmojiView: View {
let visualisation: EmojiVisualisation
var body: some View {
Text(visualisation.text)
.navigationTitle("Visualise \(visualisation.count)")
}
// Models
struct NumberList: Hashable {
let range: Range<Int>
}
struct EmojiVisualisation: Hashable {
let emoji: String
let count: Int
var description: String {
Array(repeating: emoji, count: count).joined()
}
}
} That would be similar to your proposal @morluna, but with the advantages of having a familiar API and allowing decoupling of screen creation. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, first off thanks @johnpatrickmorgan for FlowStacks! It's such a nice pattern to work with and I use it in all my personal projects.
I'm starting to brainstorm ideas for how FlowStacks could incorporate some of the iOS 16 improvements around navigation. First off I'll do a quick example of how I use FlowStacks today and then I'll add an example of what I have in mind. Looking for some feedback or improvements :) Thanks all.
Example of how I use FlowStacks today:
Click to expand!
New
DestinationRouter
suggestionMy idea is to create a new "Router" view, which I call
DestinationRouter
for lack of a better name. Here is the definition:Then we could "refactor" the snippet in the previous section like this:
The biggest differences here are:
DestinationRouter
.embedInNavigation
appears at the view level instead of the "Screen" level.Conclusion
I know there may be even better improvements, but hoping this can start some sort of conversation!
Beta Was this translation helpful? Give feedback.
All reactions