Replies: 1 comment
-
|
I have a version that respects nil for presentation dismissal, but that requires callbacks in the navigation tree and that breaks state restoration. Still thinking about that one In the meantime, a common pattern for those who want callback handlers is to have action buttons pass the navigator into the method in question... struct RootView: View {
@State private var viewModel = RootViewModel()
var body: some View {
ManagedNavigationStack { navigator in
VStack {
Button("Navigate to A") {
viewModel.navigateToA(via: navigator)
}
}
.padding()
.navigate(to: self.$viewModel.destination)
}
}
}
@Observable
final class RootViewModel {
var destination: Destinations?
func navigateToA(via navigator: Navigator) {
self.destination = .a {
navigator.dismissAnyChildren()
}
}
}You might look into Checkpoints as an alternative return mechanism. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m trying to make the app use state-driven navigation. Specifically, I want to present sheets and full-screen covers using an optional enum as the navigation state.
Based on the approach recommended here
, I tried using the navigate(to:) method. However, it’s not behaving as I expected, so I think I might be missing something.
What I’m doing is setting the destination object to a value, which correctly triggers the sheet presentation. Inside that sheet, I inject an onBack closure. When the back button is tapped, that closure sets the parent’s destination back to nil.
I would expect the sheet to dismiss at that point, but nothing happens.
After some investigation, I noticed that NavigateToModifier sets the destination to nil automatically after the navigation occurs. That made me wonder how I can achieve the behavior I’m describing, and whether it’s even possible to do so with this library.
Beta Was this translation helpful? Give feedback.
All reactions