-
I wonder if anything bad could possible happen if we simply pass the Navigator into ScreenModel? Sometimes we want to open different screens depend on data (is user is admin) or it could potentially help with implementation of the logout for 401 users.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You shouldn't do that, if the user puts the app in the background for a while, Jetpack Compose removes the UI so the Navigator won't survive, but the ScreenModel will. Doing this will make you always have a reference to the old navigator, and on restore will make it not work because its not the same navigator instance. |
Beta Was this translation helpful? Give feedback.
-
I'm trying out Voyager for the first time, and from experience having to navigate from views is much more mess-prone than navigating from viewmodels. I ran into the very problem @Syer10 mentioned, so I decided to
And then navigating from the model worked even after configuration changes and process death. The first problem I think would be figuring out a way to enforce this at compile time, as forgetting it would crash in runtime. At the moment, I'll use this extension method and forbid the original one with something like Detekt maybe.
|
Beta Was this translation helpful? Give feedback.
You shouldn't do that, if the user puts the app in the background for a while, Jetpack Compose removes the UI so the Navigator won't survive, but the ScreenModel will. Doing this will make you always have a reference to the old navigator, and on restore will make it not work because its not the same navigator instance.