VectorizedAnimationSpec

Known indirect subclasses
VectorizedDurationBasedAnimationSpec

Base class for VectorizedAnimationSpecs that are based on a fixed durationMillis.

VectorizedFloatAnimationSpec

A convenient implementation of VectorizedFloatAnimationSpec that turns a FloatAnimationSpec into a multi-dimensional VectorizedFloatAnimationSpec, by using the same FloatAnimationSpec on each dimension of the AnimationVector that is being animated.

VectorizedKeyframesSpec

VectorizedKeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.e. different keyframes).

VectorizedRepeatableSpec

This animation takes another VectorizedDurationBasedAnimationSpec and plays it iterations times.

VectorizedSnapSpec

VectorizedSnapSpec immediately snaps the animating value to the end value.

VectorizedSpringSpec

VectorizedSpringSpec uses spring animations to animate (each dimension of) AnimationVectors.

VectorizedTweenSpec

VectorizedTweenSpec animates a AnimationVector value by interpolating the start and end value, in the given durationMillis using the given easing curve.


VectorizedAnimationSpecs are stateless vector based animation specifications. They do not assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the configuration that is particular to the type of the animation. easing and duration for VectorizedTweenSpecs, or spring constants for VectorizedSpringSpecs. Its stateless nature allows the same VectorizedAnimationSpec to be reused by a few different running animations with different starting and ending values. More importantly, it allows the system to reuse the same animation spec when the animation target changes in-flight.

Since VectorizedAnimationSpecs are stateless, it requires starting value/velocity and ending value to be passed in, along with playtime, to calculate the value or velocity at that time. Play time here is the progress of the animation in terms of milliseconds, where 0 means the start of the animation and getDurationNanos returns the play time for the end of the animation.

Note: For use cases where the starting values/velocity and ending values aren't expected to change, it is recommended to use Animation that caches these static values and hence does not require them to be supplied in the value/velocity calculation.

See also
Animation

Summary

Public functions

Long
getDurationNanos(initialValue: V, targetValue: V, initialVelocity: V)

Calculates the duration of an animation.

Cmn
open V
getEndVelocity(initialValue: V, targetValue: V, initialVelocity: V)

Calculates the end velocity of the animation with the provided start/end values, and start velocity.

Cmn
V
getValueFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
)

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

Cmn
V
getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
)

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Cmn

Public properties

Boolean

Whether or not the VectorizedAnimationSpec specifies an infinite animation.

Cmn

Public functions

getDurationNanos

fun getDurationNanos(initialValue: V, targetValue: V, initialVelocity: V): Long

Calculates the duration of an animation. For duration-based animations, this will return the pre-defined duration. For physics-based animations, the duration will be estimated based on the physics configuration (such as spring stiffness, damping ratio, visibility threshold) as well as the initialValue, targetValue values, and initialVelocity.

Parameters
initialValue: V

start value of the animation

targetValue: V

end value of the animation

initialVelocity: V

start velocity of the animation

getEndVelocity

open fun getEndVelocity(initialValue: V, targetValue: V, initialVelocity: V): V

Calculates the end velocity of the animation with the provided start/end values, and start velocity. For duration-based animations, end velocity will be the velocity of the animation at the duration time. This is also the default assumption. However, for physics-based animations, end velocity is an AnimationVector of 0s.

Parameters
initialValue: V

start value of the animation

targetValue: V

end value of the animation

initialVelocity: V

start velocity of the animation

getValueFromNanos

fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
): V

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTimeNanos: Long

time since the start of the animation

initialValue: V

start value of the animation

targetValue: V

end value of the animation

initialVelocity: V

start velocity of the animation

getVelocityFromNanos

fun getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
): V

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTimeNanos: Long

time since the start of the animation

initialValue: V

start value of the animation

targetValue: V

end value of the animation

initialVelocity: V

start velocity of the animation

Public properties

isInfinite

val isInfiniteBoolean

Whether or not the VectorizedAnimationSpec specifies an infinite animation. That is, one that will not finish by itself, one that needs an external action to stop. For examples, an indeterminate progress bar, which will only stop when it is removed from the composition.