Fix GestureNavDecoration dropping saveable/retained state on back gestures #1089
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue is caused by both the iOS and Android implementations displaying multiple back records at the same time, for mostly the same reason (so that swipes display the previous record). Both implementations use a
Transition
to enable one-shot back events (button presses, etc) to display an appropriate animation, which means that we have 2 places where the previous record could be attached to composition.This works mostly fine, but does come with an issue with how we handle state, which is through
movableContentOf
. Movable content can only be attached to composition once, whilst still moving all of the state around. If the content is attached twice, the second time will create a new copy of the content (like a normal composable lambda), which is why the state was 'being dropped'. It wasn't actually being dropped in the state registries, the content just didn't get access to them.Back to our use case. In the typical 'user swipes for back' scenario, we manually display the previous record content so that the user sees it as appropriate. However, when transition is run the
AnimatedContent
is responsible for composing both sides of the transition, and thus both the current and previous content will be attached to composition. Hopefully you can see here the issue: we were attaching the previous content twice, once in theAnimatedContent
and again by our manual call.The fix is pretty simple, only attach the previous content once by keeping the transition and manual composition calls exclusive.
Fixes #985.