https://kotlinlang.org logo
#compose
Title
# compose
a

Alex

05/30/2022, 8:09 PM
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

Icyrockton

05/30/2022, 10:08 PM
launcheffect
d

Doris Liu

05/31/2022, 12:45 AM
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

Alex

05/31/2022, 12:03 PM
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

Doris Liu

05/31/2022, 4:13 PM
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. 🙂
2 Views