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] Feature Request - Navigation Animation Listener #1445

Closed isles1217 closed 1 year ago

isles1217 commented 1 year ago

Description I'd love it if an animation listener could be added to the AnimatedNavHost component. I use some components that have a scale modifier, and I'd like to prevent those composables from scaling until the navigation animation completes. The reason being, is that components that scale get put on a separate drawing layer, and end up looking "cut off" until the animation is complete.

Steps to reproduce

  1. Set up two full screen composables (screens) that navigate between each other, each containing a single button on them.
  2. Apply a .scale(1.2f) modifier to the button.
  3. Navigate between the composables.
  4. Note that the buttons appear to be cutt-off or squished, until the navigation is complete, resulting in a "pop-in" once the animation is done.

Additional context I imagine the simplest solution here would be to attach an animation listener to the screen transition, that I could use to let my composables know when they're allowed to scale (after the transition animation is complete).

ianhanniballake commented 1 year ago

Navigation Compose already has a listener for this - the Lifecycle of the NavBackStackEntry only reaches RESUMED when the animation completes.

The DisposableEffect guide actually uses listening for lifecycle events as its example. b/209684871 tracks exposing Lifecycle.State as Compose State much easier, which would help with this case as well.

Note that we have also talked about listening to observing navigation transition state in #633, something which we also added APIs to do for listening to transition effects outside of an individual destination (e.g., for cases like a bottom nav, etc. that is shared across all destinations).