-
-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access navigator
in root Navigator's onBackPressed
handler?
#333
Comments
I think that it should expose |
You can't. This is a common use case, the There is this open PR that fixs some bugs related to nested navigators #273. I plan to get on back on it soon. Solution I propose for now, that is what I'm currently using it in personal projects is to replicated what Voyager navigators does under the hood. This snippet was taken from the Voyager implementation here Line 11 in a28fd4d
Navigator(...) { navigator ->
BackHandler(
enabled = navigator.canPop || navigator.parent?.canPop ?: false,
onBack = {
// DO anything here with the `navigator`
if (navigator.pop().not()) {
navigator.parent?.pop()
}
}
)
CurrentScreen()
} |
You don't need to access
In your Screen, use (you can access navigator in screen easily)
|
I have a very easy case, just accessing
navigator
instance inonBackPressed
handler. BecauseLocalNavigator.currentOrThrow
need inComposable
context, I can't use it in that handler. how to do that?Example:
Thanks~
The text was updated successfully, but these errors were encountered: