animateTo
Function
Common
public suspend fun <T, V : AnimationVector> AnimationState<T, V>.animateTo(
targetValue: T,
animationSpec: AnimationSpec<T> = spring(),
sequentialAnimation: Boolean = false,
block: AnimationScope<T, V>.() -> Unit = {},
)
Target based animation that takes the value and velocity from the AnimationState
as the
starting condition, and animate to the targetValue
, using the animationSpec
. During the
animation, the given AnimationState
will be updated with the up-to-date value/velocity, frame
time, etc.
Parameters
targetValue | The target value that the animation will animate to. |
animationSpec | The animation configuration that will be used. spring by default. |
sequentialAnimation | Indicates whether the animation should use the AnimationState.lastFrameTimeNanos as the starting time (if true), or start in a new frame. By default, sequentialAnimation is false, to start the animation in a few frame. In cases where an on-going animation is interrupted and a new animation is started to carry over the momentum, using the interruption time (captured in AnimationState.lastFrameTimeNanos ) creates a smoother animation. |
block | Will be invoked on every frame, and the AnimationScope will be checked against cancellation before the animation continues. To cancel the animation from the block , simply call AnimationScope.cancelAnimation . After AnimationScope.cancelAnimation is called, block will not be invoked again. The animation loop will exit after the block returns. All the animation related info can be accessed via AnimationScope . |