Open pitampoudel opened 1 month ago
I've encountered this as well, by the way. I have Voyager pretty deeply integrated into my app, so I may just end up having to submit a fix PR myself here sometime soon.
Have you tried setting disposeNestedNavigators = false
in the root navigator?
@shpasha Yeah, that worked for me. But It would be great if there was documentation on why this parameter is for
@pitampoudel how are you obtaining the parent navigator? I am setting the disposeNestedNavigators = false
flag and still losing the state from inside my tab when navigating. I'm wondering if I'm getting it the wrong way.
To obtain the parent navigator I am using this => val parentNavigator = LocalNavigator.currentOrThrow.parent and is working for me. @creativedrewy
I am currently working on a project that uses Voyager for navigation. My application has a hierarchical structure of navigators and screens, which is causing an issue with state preservation.
Here’s the structure of my navigators and screens:
A root Navigator is present at the main level. Inside this root Navigator, there is a HomeScreen. Within the HomeScreen, I have another TabNavigator which contains three tabs: TabA, TabB, and TabC. In TabA, I have constructed a TabAScreenModel using the getScreenModel() composable function. This TabAScreenModel is provided by Koin.
The issue arises when I navigate from HomeScreen (which is currently displaying TabA) to another screen (ScreenX) using the parent navigator. ScreenX is not inside the TabNavigator, but is instead a part of the root navigator.
When I navigate back to HomeScreen from ScreenX, the TabAScreenModel associated with TabA is destroyed and re-constructed. This results in the loss of its previous state.
I would like to preserve the existing state of TabAScreenModel when navigating away from HomeScreen and then returning to it. Any guidance or suggestions on how to achieve this would be greatly appreciated.