Previously, i was kicking off an animation at load using
DisposableEffect
but it’s necessary for me to switch it to
LaunchedEffect
and, more importantly, I was using an
onEnd
callback in
animateTo
. It looked like this:
DisposableEffect(powerValue) {
animatedProgress.snapTo(0f)
animatedProgress.animateTo(1f, tween(durationMillis = 200), onEnd = { _: AnimationEndReason, _: Float ->
setPowerValueWas(powerValue)
animatedProgress.snapTo(0f)
})
onDispose {}
}
Since
onEnd
was removed, would an appropriate way of handling this be the use of async/await to examine
endReason
?
LaunchedEffect(powerValue) {
animatedProgress.snapTo(0f)
val result = async { animatedProgress.animateTo(1f, tween(durationMillis = 200)) }.await()
when (result.endReason) {
AnimationEndReason.Finished -> {
setPowerValueWas(powerValue)
animatedProgress.snapTo(0f)
}
}
}