Skip to content
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

State Preservation Issue with Nested Navigators in Voyager #383

Open
pitampoudel opened this issue Mar 29, 2024 · 5 comments
Open

State Preservation Issue with Nested Navigators in Voyager #383

pitampoudel opened this issue Mar 29, 2024 · 5 comments
Labels
docs Improvements or additions to documentation state restauration

Comments

@pitampoudel
Copy link

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.

@creativedrewy
Copy link

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.

@shpasha
Copy link
Contributor

shpasha commented Apr 5, 2024

Have you tried setting disposeNestedNavigators = false in the root navigator?

@pitampoudel
Copy link
Author

@shpasha Yeah, that worked for me. But It would be great if there was documentation on why this parameter is for

@DevSrSouza DevSrSouza added docs Improvements or additions to documentation state restauration labels Apr 7, 2024
@creativedrewy
Copy link

@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.

@pitampoudel
Copy link
Author

To obtain the parent navigator I am using this => val parentNavigator = LocalNavigator.currentOrThrow.parent and is working for me.
@creativedrewy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation state restauration
Projects
None yet
Development

No branches or pull requests

4 participants