google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

[Navigation Animation] Different animation behaviour between fragments and compose #1572

Closed Denis55ka closed 1 year ago

Denis55ka commented 1 year ago

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

Expected behavior ExitTransition applies to the previous composable screen in the back stack.

ianhanniballake commented 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 the enterTransition.
  • popExitTransition: specifies the animation that runs when this destination leaves the screen after you pop it off the back stack. This defaults to the exitTransition.

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.