Closed Denis55ka closed 1 year ago
These APIs follow the same pattern as the Fragment Transition APIs, but with more flexibility. There is purposefully no support for attaching animations to individual navigate
operations - they are part of the structure of your graph.
As per the blog post on Animations:
This control comes in the form of four new parameters found on every composable destination:
enterTransition
: specifies the animation that runs when you navigate() to this destination.exitTransition
: specifies the animation that runs when you leave this destination by navigating to another destination.popEnterTransition
: specifies the animation that runs when this destination re-enters the screen after going through a popBackStack(). This defaults to theenterTransition
.popExitTransition
: specifies the animation that runs when this destination leaves the screen after you pop it off the back stack. This defaults to theexitTransition
.
Each individual composable
is only controlling its own transitions based on what screen you are coming from (in the case of entering transitions) or going to (in the case for exiting transitions). That's exactly the same thing as Fragment Transitions.
If you want to set an exitTransition
for any screen within a particular graph when going to your individual screen, you'd just write exactly that - override enterTransition
and check the targetState.destination
.
FWIW, strongly consider using slideIntoContainer
and slideOutOfContainer
for sliding content completely off the screen - that'll do all of the width/height calculation work for you.
Description In fragments when we specify an exitTransition for a fragment transaction, this transition applies for the previous fragment in the back stack.
In compose when we specify exitTransition (by composable() graph builder) this animation applies for the current screen during it exit animation (when it will be closed by the next screen).
Is it really expected behaviour?
Steps to reproduce
specify default animation for AnimatedNavHost, e.g: enter =
slideInHorizontally(initialOffsetX = { width -> width })
exit =slideOutHorizontally(targetOffsetX = { width -> -(width * .2).roundToInt() })
for one screen in composable graph builder specify different animation, e.g: enter =
slideInVertically(initialOffsetY = { height -> height })
exit =slideOutVertically(targetOffsetY = { height -> height })
Expected behavior ExitTransition applies to the previous composable screen in the back stack.