Skip to content

Fix reset root #1995

Merged
stagg merged 16 commits intomainfrom
j-fix-resetroot-2
Mar 19, 2025
Merged

Fix reset root #1995
stagg merged 16 commits intomainfrom
j-fix-resetroot-2

Conversation

@stagg
Copy link
Copy Markdown
Collaborator

@stagg stagg commented Mar 12, 2025

🤞🏻 this fixes #1285

Underlying issue was caused by a new MovableContent getting created for a backstack entry that was still in the composition due to animations. The new movable content is effectively the same as the old one, same composite keys etc, so any keyed ReusableContent would get reused without being disposed. This was causing the check in SaveableStateHolderImpl to be replayed in new onRemembered call on the same reused instance.

Fix is to fully track the movable content being used, and remove it from our provider reuse map when it is no longer going to be used. Allowing the content to be correctly reparented.

See #2001 for a sample app an test for this

public val topRecord: R?

/** The bottom-most record in the [BackStack], or `null` if the [BackStack] is empty. */
public val rootRecord: R?
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to help check the current root screen without having to iterate the whole back stack.

tabs.forEach { tab ->
val selected = tab == backStack.rootRecord?.screen
Text(

@stagg stagg marked this pull request as ready for review March 18, 2025 22:12
@stagg stagg requested a review from ZacSweers March 18, 2025 22:12
@stagg stagg added this pull request to the merge queue Mar 19, 2025
Merged via the queue into main with commit 55c11e7 Mar 19, 2025
5 checks passed
@stagg stagg deleted the j-fix-resetroot-2 branch March 19, 2025 01:12
@itsandreramon
Copy link
Copy Markdown

great stuff!

github-merge-queue Bot pushed a commit that referenced this pull request Mar 19, 2025
Follow up to #1995

Adds a sample app for bottom bar style navigation that is reliant on
`resetRoot`, with a corresponding test.

### Demo


https://github.com/user-attachments/assets/0d20bc30-b256-413d-b449-4a80b97bf7e8
@MichaelEvans
Copy link
Copy Markdown
Contributor

I tested my app with the 0.28.0 snapshots and this seems to have resolved my issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast switching between tab bars causing creating new tab instead of restoring previous one

4 participants