adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.27k stars 109 forks source link

Nested navigators inside Tabs don't get disposed when the TabNavigator gets disposed. #402

Open hristogochev opened 2 weeks ago

hristogochev commented 2 weeks ago

When disposing of a TabNavigator, the nested navigators inside each Tab don't get disposed. This means that the ScreenModels inside each navigator don't get disposed as well.

I've solved the problem by taking the source code of the voyager-tab-navigator dependency and making some minimal changes.

The solution is published in this gist: Fix for Voyager TabNavigator not disposing of nested navigators.

Essentially, the solution involves mapping the nested navigator created inside each Tab to the Tab itself so that it can be disposed of when the TabNavigator is disposed.

If you need more than one nested navigator inside a tab, feel free to make the navigators a list instead, but I think this is enough.

This also helps partly resolve https://github.com/adrielcafe/voyager/issues/396.