Implicit Navigation and state restoration.
I've a question, given the exemple here: https://bumble-tech.github.io/appyx/navigation/implicit-navigation/#use-case-2
We listen to the UserRepository in the RootNode to then branch the right LoggedInNode or NotLoggedInNode.
We make the listening lifecycle aware so we stop listening to UserRepository when RootNode is destroyed.
init {
userRepository.isLoggedIn()
.distinctUntilChanged()
.onEach { isLoggedIn ->
if (isLoggedIn) {
backstack.replace(NavTarget.LoggedInNode)
} else {
backstack.replace(NavTarget.NotLoggedInNode)
}
}
.launchIn(lifecycleScope)
}
So, if we provoke a configuration change, the activity and all the nodes will be destroyed and recreated. The right node will be restored, but we'll also start listening to the UserRepository again, so we'll replace the restored Node by a new one.
Not sure how we can manage this case, any idea?
Hi @ganfra to fix this quickly without changing presentation model to survive config changes like VM you can try to:
- Use
newRootinstead ofreplaceif it's logically correct. It will not replace existingnavTargetif the new one is equal. - If you can't use
newRoot, you can manually check currently active element before replacing it
Thanks for the intels!
I'd avoid using VM as I'd like to get all my dependencies injected into my nodes through dagger... How do you manage config change in your apps?
We don't use VM either. Our business logic classes implement savedInstanseState plugin to save their states.
@KovalevAndrey : Last question then, how do you handle things like: launching coroutines scoped to the node but which survive config change? (without VM I mean)