adrielcafe / voyager

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

Screen State not getting retained #372

Open techjd opened 1 month ago

techjd commented 1 month ago

I am working on a project with 5 tabs. I have a Home tab, which displays a list of products. Clicking on any product takes you to the detail page. Initially, my problem was in navigating to the detail screen. It works perfectly with nested navigation, but I wanted to hide the bottom nav bar and top app bar.

Initially, I followed the approach mentioned in this discussion thread: https://github.com/adrielcafe/voyager/discussions/322.

It did work, but I had to pass lambda as a parameter to the screen, which caused crashes on Android due to java.lang.RuntimeException: Parcelable encountered IOException writing serializable object.

I quickly changed my approach and navigated to the DetailedScreen using the parent navigator: https://github.com/adrielcafe/voyager/issues/204#issuecomment-1723488807.

However, I am facing an issue where the screen state is not retained when navigating back on Android, although on iOS, the screen state is retained. This problem is also faced in rest of the tabs. Are there any fixes for this?

You can observe in the video that the list state is getting changed on Android. My current approach can be found here

https://github.com/adrielcafe/voyager/assets/28820868/daefc1de-0719-4eeb-88cf-70459f846cd0

nvkleban commented 1 month ago

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

DevSrSouza commented 1 month ago

All Voyager screen has to be serializable in a Bundle, this means that you need to all parameters of your Screen for Android to be or Java Serializable or Parcelable.