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

Tash

02/17/2021, 9:18 PM
Trying to create an “animation/modifier state” class similar to SwipeableState, with `AnimatedFloatModel`s inside. Is there a way to animate multiple
AnimatedFloatModel
s together and then listen for the end of the collective animation?
Copy code
@Stable
class FooDragState { 
 val animatedOffsetX = AnimatedFloatModel(initialValue = 0f, clock)
 val animatedOffsetY = AnimatedFloatModel(initialValue = 0f, clock)
 
 (animatedOffsetX, animatedOffsetY).animateTo(1f, animationSpec, onEnd = { /** do something **/ })
}
Oop, turns out `AnimatedFloat*`s are deprecated in favor of
Animatable
as of
alpha12
. Looks like the
animateTo(...)
functions are now
suspend
functions. Perhaps animating two
Animatable
s together would look like launching two
animateTo()
s and then awaiting the completion of both jobs.
d

Doris Liu

02/17/2021, 10:31 PM
Perhaps animating two 
Animatable
 s together would look like launching two 
animateTo()
 s and then awaiting the completion of both jobs.
Yes. That is correct. If you
launch
them from the same
coroutineScope { ... }
, you can just wait for the coroutineScope to finish. 🙂
t

Tash

02/17/2021, 10:34 PM
Thank you @Doris Liu! Really smart idea making these suspend functions, reasoning about them feels more intuitive. Will try this out
👍 1
2 Views