-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fix dropping back stack retained state on Android Activity rotations #1063
Fix dropping back stack retained state on Android Activity rotations #1063
Conversation
0161ea8
to
187d090
Compare
63872fe
to
cabf667
Compare
This reverts commit 190d8e7.
We store the RetainedStateRegistries for each back stack entry into an 'navigation content' RetainedStateRegistry. If we don't do this, those registries would be stored directly in the current LocalRetainedStateRegistry value, which will mostly likely be the continuityRetainedStateRegistry. On Android, that continuityRetainedStateRegistry will drop any 'unclaimed' values when the host Activity is recreated. Since records on the back stack aren't attached to composition, they can't claim their retained registries and thus we drop all of the state for the record. See slackhq#1046. Using this 'navigation content' registry means that _it_ will be stored in the continuityRetainedStateRegistry instead, and any back stack record registries stored within the 'navigation content' registry. The difference is that NavigableCircuitContent will be attached to composition for the entire lifetime that we care about, and thus will be able to save/claim the 'navigation content' registry on recreations. Since any back stack registries are nested in this 'navigation content' registry, everything is saved/claimed correctly.
…ons for good measure
7b2c8ff
to
5e40c70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. We currently don't run any instrumentation tests on CI (we'd moved them all to run in robolectric), but I can work on adding that CI support back in a separate PR if you think these couldn't also move to Robolectric
if (backstack.size > 0) { | ||
if (backstack.isEmpty) return | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried porting this to Robolectric but couldn't get the original issue to fail. Rotations/recreations are tricky to simulate so not surprising tbh. |
We store the RetainedStateRegistries for each back stack entry into an 'navigation content'
RetainedStateRegistry
. If we don't do this, those registries would be stored directly in the currentLocalRetainedStateRegistry
value, which will mostly likely be thecontinuityRetainedStateRegistry
. On Android, thatcontinuityRetainedStateRegistry
will drop any 'unclaimed' values when the host Activity is recreated. Since records on the back stack aren't attached to composition, they can't claim their retained registries and thus we drop all of the state for the record.Using this 'navigation content' registry means that it will be stored in the
continuityRetainedStateRegistry
instead, and any back stack record registries stored within the 'navigation content' registry. The difference is thatNavigableCircuitContent
will be attached to composition for the entire lifetime that we care about, and thus will be able to save/claim the 'navigation content' registry on recreations. Since any back stack registries are nested in this 'navigation content' registry, everything is saved/claimed correctly.Added an Android instrumentation test to stop this regressing in the future.
Fixes #1046