What the idiomatic way of playing an `animation th...
# compose
u
What the idiomatic way of playing an
animation that is a result of a event
? Think of hitting a button and exploding confetti. (So not a function of a state - like changing alpha to a certain value and staying there)
c
z
More generally, launching a coroutine and running an animation. Whether that’s with
Animatable.animateTo
, the lower-level
animate
function, or completely from scratch with frame callbacks like Christian suggested (just be aware of
MotionDurationScale
in that case).
u
but it has to be inside a Launched effected keyed by the event?
z
No, use
rememberCoroutineScope
to get a
CoroutineScope
and then in your event handler call
launch
on that.
u
I see say its
isPlaying bool
state which gets toggled and I want to play the vector morph animation of the icon in the button based on that , is that when I'd use
LaunchedEffect(isPlaying)
?
z
In general if you want to run some coroutine work when a state changes better to use a long-running
LaunchedEffect
with
snapshotFlow
.