KaustubhPatange/navigator

[Navigator Compose] Nested navigation does not save saveables in `SaveableStateHolder` across process death.

KaustubhPatange opened this issue · 3 comments

While testing the sample app I encountered that the scroll state of LazyColumn is not restored across process death. It works when moved into the first navigator.Setup route.

Upon investigation, it seems like the SaveStateRegistry is properly being stored into bundle at onSaveStateInstance but is not correctly restored.

After a lot of testing & researching (literally a lot), I came up with the fix but it works when there are no animations. Generally even though animations are enabled the root navigation is always restored no matter what! But the nested one does not get restored after process death.

It seems like the issue lies with the Compose itself, read more here.

Follow up on this issue it seems like the issue is with the destination classes themselves. In nutshell, we cannot use class or object in a sealed class to represent destination as they do not have stable hashCodes() which Compose uses to determine if the keys are the changed or not. This is not the case with the data classes because compiler generates equals() and hashCode() methods for us.

Currently, the only way to declare no-arg destination is to use a data class with a single default private parameter as shown in the Quick Setup.