Skip to content
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 GestureNavDecoration dropping saveable/retained state on back gestures #1089

Merged
merged 3 commits into from
Jan 1, 2024

Conversation

chrisbanes
Copy link
Contributor

@chrisbanes chrisbanes commented Dec 31, 2023

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 the AnimatedContent 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.

@chrisbanes chrisbanes changed the title [WIP] Fix GestureNavDecoration dropping saveable/retained state on back gestures Fix GestureNavDecoration dropping saveable/retained state on back gestures Jan 1, 2024
@chrisbanes chrisbanes marked this pull request as ready for review January 1, 2024 17:36
@chrisbanes
Copy link
Contributor Author

Another manual merge needed I think (once CI finishes)

@ZacSweers ZacSweers merged commit c8e16a9 into slackhq:main Jan 1, 2024
2 of 3 checks passed
@ZacSweers ZacSweers deleted the cb/gesture-nav-lose-state branch January 1, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

State Retain and padding problem on Android 14
2 participants