Chris Grigg
02/26/2021, 8:50 PManimatedFloat
to remember { Animatable(initialValue = 0f) }
. Changing this involves replacing an onEnd
callback and I’m using async/await for it, I was wondering if this is a good way of approaching it? Complete code snippets are below in the reply thread.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)
}
}
}
Dominaezzz
02/26/2021, 8:53 PMChris Grigg
02/26/2021, 8:55 PMDominaezzz
02/26/2021, 8:55 PMChris Grigg
02/26/2021, 8:55 PMDoris Liu
02/26/2021, 10:33 PMAnimatable
, you don't even need to check the end reason - the animateTo
only returns when it finishes (or reaches bounds). In the case of interruption, there'll be a CancellationException
thrownChris Grigg
02/26/2021, 10:33 PM