Replies: 5 comments
-
I added some pause/resume sample code to main as I was fiddling with this, but honestly, I'm not sure that's a navigator problem. Why doesn't standard SwiftUI code work here? @main
struct NavigatorExpApp: App {
@Environment(\.navigator) var navigator: Navigator
@State var isLoggedIn: Bool = true
var body: some Scene {
WindowGroup {
ManagedNavigationStack {
if isLoggedIn {
HomePageView()
.navigationDestination(Routes.self)
} else {
LogInView()
}
}
.environment(\.navigator, Navigator(configuration: configuration))
}
}
} |
Beta Was this translation helpful? Give feedback.
-
What I'm trying to do is a little different. I don't want to set a different initial view based on the logged in state. I'm trying to keep the same navigation stack and push the user to a view that is ahead in the stack based on the user's logged in status. Let me clarify. New users open the app and they land on the For already logged in users, I want to directly push them onto the This is because when/if the user logs out (say by tapping a button in the I was trying to achieve this when I came across the issue described in the original post. |
Beta Was this translation helpful? Give feedback.
-
Hey all, Screen.Recording.2025-01-21.mov
The main idea is the coordinator view, which simply switches views based on a condition. You’ll need to wrap it like this: But @hmlongco, have you ever thought of a better way to set the root view like we used to with
P.S. The solution I shared does have some side effects! For example, if you have a navigation title, it will end up looking like this: Screen.Recording.2025-01-21.with.Navigation.Title.mov |
Beta Was this translation helpful? Give feedback.
-
The biggest problem I have at the moment is that providing an initial navigation path interferes with navigation checkpoints. |
Beta Was this translation helpful? Give feedback.
-
Like when we want to perform an internal action without notifying the delegate? |
Beta Was this translation helpful? Give feedback.
-
Hi, first off thanks for the great library.
I'm looking for some suggestions on how to implement this particular scenario. This is a quite common pattern. Say you have a
LoginView
andHomeView
. If it's a brand new user, they land on theLoginView
. If they've previously logged in, they are navigated directly to theHomeView
. However, the first view of the stack still needs to beLoginView
because if the user logs out, they need to be popped back to theLoginView
but the user shouldn't see theLogInView
when opening the app.My current setup is this.
I modified it (this is a simplified version) to do the check in the initializer to see if the user is logged in and push to
HomeView
using thenavigator.send()
method.But I'm getting the following error where I'm calling the
send()
method.That probably be because I'm trying to access the
navigator
environment variable before it's injected into the view hierarchy.I then tried to encapsulate everything with a
ContainerView
and move this checking logic one level down but I'm still getting the same error.I'm not sure if I'm going about this the right way. Is there a better way to achieve this?
Any help is appreciated. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions