Skip to content

Conversation

@kvaster
Copy link
Contributor

@kvaster kvaster commented May 18, 2025

Currently type of transition animation is determined only by backstack depth (and by root screen change), but this doesn't cover complex backstack changes - i.e. when you pop several screen and add one more on top.

This PR always treat new screens as GoTo animation. Pop animation will be played only if we're back to screen which was already in a back stack.

Fixes #2075

Probably screem, rootScreen, backStackDepth should be removed from AnimatedNavState - we can get them from backStack property. Also backStackDepth may be removed from other functions.

@salesforce-cla
Copy link

Thanks for the contribution! Before we can merge this, we need @kvaster to sign the Salesforce Inc. Contributor License Agreement.

@kvaster
Copy link
Contributor Author

kvaster commented May 18, 2025

It look like salesforce-cla bugged... I've signed the CLA, it answered with an error and now it is saying me that CLA is already signed...

@stagg
Copy link
Collaborator

stagg commented May 21, 2025

Ya the cla bot is bugged, I'll fix it here

@stagg stagg closed this May 21, 2025
@stagg stagg reopened this May 21, 2025
} else if (targetState.screen == initialState.screen) {
// Target screen has not changed, probably we should not show any animation even if the back stack is changed
return@spec EnterTransition.None togetherWith ExitTransition.None
} else if (initialState.backStack.contains(targetState.screen)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The contains here might not work as expected if we navigate to a screen already in the backstack.
So we probably want to compare the full record using the full backstack (the args given to us in DefaultAnimatedState), and determine if the initial and target backstacks have diverged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry for such late answer...

I was thinking about how exactly we can/should compare backstacks. And I really think that 'contains' covers really more situations. If target screen was already in stack - we're moving back. In other case screen is new - it's GoTo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also record itself contains only Screen...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry, I wasn't clear with this:

if we navigate to a screen already in the back stack.

If we're navigating to a new ScreenA instance with goTo and an equals ScreenA already exists in the backstack.

listOf(ScreenC, ScreenB, ScreenA)
goTo(ScreenA)
listOf(ScreenA, ScreenC, ScreenB, ScreenA)

Using Record in this case is useful because it'll contain a unique key per back stack entry.

/**
* A value that identifies this record uniquely, even if it shares the same [screen] with
* another record. This key may be used by [BackStackRecordLocalProvider]s to associate
* presentation data with a record across composition recreation.
*
* [key] MUST NOT change for the life of the record.
*/
public val key: String

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I will update my PR.

@kvaster kvaster force-pushed the navigation-animation branch from 1a22ade to e2e7d7f Compare July 24, 2025 18:58
@kvaster
Copy link
Contributor Author

kvaster commented Jul 24, 2025

I've updated my PR. Now NavArgument is used to compare stacks.
One more refactoring will be on the way if this PR will be OK. backStackDepth passed is not used anymore, cause backStack itself can tell this to us if needed.

@stagg
Copy link
Collaborator

stagg commented Jul 24, 2025

I've updated my PR. Now NavArgument is used to compare stacks. One more refactoring will be on the way if this PR will be OK. backStackDepth passed is not used anymore, cause backStack itself can tell this to us if needed.

Awesome, looks good! Thanks for making the record changes 🚀 I'm cool with removing backStackDepth as part of this PR as well.

@kvaster
Copy link
Contributor Author

kvaster commented Jul 25, 2025

backStackDepth propogation removed.

@kvaster
Copy link
Contributor Author

kvaster commented Jul 28, 2025

I'm sorry, forgot to run tests and to commit code formatting changes. Now it should be OK.

Copy link
Collaborator

@stagg stagg left a comment

Choose a reason for hiding this comment

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

The emulator error is a bug with the script, verified it locally and we're all clear ✅
Thanks so much for these changes! 🚀

@kvaster kvaster force-pushed the navigation-animation branch from cca27f4 to d6fff08 Compare July 29, 2025 06:23
@kvaster
Copy link
Contributor Author

kvaster commented Jul 29, 2025

I've made rebase and resolved conflicts with main branch.

@stagg stagg added this pull request to the merge queue Jul 29, 2025
Merged via the queue into slackhq:main with commit ecbf1d3 Jul 29, 2025
5 checks passed
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.

No screen transition animation in case of backstack depth is not changed

2 participants