AnimationState

class AnimationState<T, V : AnimationVector>(val typeConverter: TwoWayConverter<T, V>, initialValue: T, initialVelocityVector: V? = null, lastFrameTimeNanos: Long = AnimationConstants.UnspecifiedTime, finishedTimeNanos: Long = AnimationConstants.UnspecifiedTime, isRunning: Boolean = false) : State<T>

AnimationState contains the necessary information to indicate the state of an animation. Once an AnimationState is constructed, it can only be updated/mutated by animations. If there's a need to mutate some of the fields of an AnimationState, consider using copy functions.

Parameters

typeConverter
initialValue

initial value of the AnimationState

initialVelocityVector

initial velocity of the AnimationState, null (i.e. no velocity) by default.

lastFrameTimeNanos

last frame time of the animation, AnimationConstants.UnspecifiedTime by default

finishedTimeNanos

the time that the animation finished successfully, AnimationConstants.UnspecifiedTime until then

isRunning

whether the AnimationState is currently being updated by an animation. False by default

Constructors

Link copied to clipboard
constructor(typeConverter: TwoWayConverter<T, V>, initialValue: T, initialVelocityVector: V? = null, lastFrameTimeNanos: Long = AnimationConstants.UnspecifiedTime, finishedTimeNanos: Long = AnimationConstants.UnspecifiedTime, isRunning: Boolean = false)

Properties

Link copied to clipboard

The time when the animation finished successfully in the System.nanoTime timebase.

Link copied to clipboard

Indicates whether the given AnimationState is for an animation that has finished, indicated by AnimationState.finishedTimeNanos having a specified value.

Link copied to clipboard

Indicates whether the animation is currently running.

Link copied to clipboard

Last frame time of the animation.

Link copied to clipboard
Link copied to clipboard
open override var value: T

Current value of the AnimationState.

Link copied to clipboard
val velocity: T

Velocity of type T, converted from velocityVector.

Link copied to clipboard

Current velocity vector of the AnimationState.

Functions

Link copied to clipboard
suspend fun <T, V : AnimationVector> AnimationState<T, V>.animateDecay(animationSpec: DecayAnimationSpec<T>, sequentialAnimation: Boolean = false, block: AnimationScope<T, V>.() -> Unit = {})

Decay animation that slows down from the current velocity and value captured in AnimationState until the velocity reaches 0. During the animation, the given AnimationState will be updated with the up-to-date value/velocity, frame time, etc. This is often used to animate the result of a fling gesture.

Link copied to clipboard
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.

Link copied to clipboard
fun <T, V : AnimationVector> AnimationState<T, V>.copy(value: T = this.value, velocityVector: V? = this.velocityVector.copy(), lastFrameTimeNanos: Long = this.lastFrameTimeNanos, finishedTimeNanos: Long = this.finishedTimeNanos, isRunning: Boolean = this.isRunning): AnimationState<T, V>

Creates a new AnimationState from a given AnimationState. This function allows some of the fields to be different in the new AnimationState.

fun AnimationState<Float, AnimationVector1D>.copy(value: Float = this.value, velocity: Float = this.velocityVector.value, lastFrameTimeNanos: Long = this.lastFrameTimeNanos, finishedTimeNanos: Long = this.finishedTimeNanos, isRunning: Boolean = this.isRunning): AnimationState<Float, AnimationVector1D>

Creates a new AnimationState of Float value type from a given AnimationState of the same type. This function allows some of the fields to be different in the new AnimationState.

Link copied to clipboard
open override fun toString(): String