hey guys, i’m migrating an `animatedFloat` to `rem...
# compose
c
hey guys, i’m migrating an
animatedFloat
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.
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:
Copy code
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
?
Copy code
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)
            }
        }
    }
d
You don't need async/await . Just call the method directly.
1
c
oh jeez, i’m fading. of course, it wouldn’t run asynchronously unless i launched a new coroutine, right?
d
Indeed.
c
of course of course
thank you
d
And yes... you could just call it directly, and examine the returned result. If you don't have bounds set on the
Animatable
, 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
thrown
c
that’s a great tip, thank you
👍 1