Is there a way to listen to the Animations of `Ani...
# compose
a
Is there a way to listen to the Animations of
AnimatedContent
? Like if I want to get notified if an animation has finished. e.g.
AnimatedContent
gets new
targetState
, animates, calls my listener when animation has finished
i
launcheffect
d
You could use the
Transition.AnimatedContent
API, and listen for when the
Transition.currentState
changes via
snapshotFlow { yourTransition.currentState }.collect {// do something with the state change}
in a
LaunchedEffect
a
That is a workable solution, I will try that, thanks @Doris Liu this should work!
Thankfully when the animation is done,
targetState
will be equal to
currentState
, so I can just listen for
targetState != currentState -> targetState == currentState
Neat 🙂
d
If you need the finished event for adding more declarative UI, you could just do
if (targetState == currentState && targetState == someSpecificState) { // some more UI here }
in a composable function. 🙂