VectorizedKeyframesSpec


VectorizedKeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.e. different keyframes). Each keyframe can be provided via keyframes parameter. VectorizedKeyframesSpec allows very specific animation definitions with a precision to millisecond.

Here's an example of creating a VectorizedKeyframesSpec animation: (keyframes and KeyframesSpec.KeyframesSpecConfig could make defining key frames much more readable.)

val delay = 120
val startValue = AnimationVector3D(100f, 200f, 300f)
val endValue = AnimationVector3D(200f, 100f, 0f)
val keyframes = VectorizedKeyframesSpec(
     keyframes = mutableMapOf (
          0 to (startValue to LinearEasing),
          100 to (startValue to FastOutLinearInEasing)
     ),
     durationMillis = 200,
     delayMillis = delay
)

The interpolation between each value is dictated by VectorizedKeyframeSpecElementInfo.arcMode on each keyframe. If no keyframe information is provided, initialArcMode is used.

See also
KeyframesSpec

Summary

Public constructors

<V : AnimationVector> VectorizedKeyframesSpec(
    keyframes: Map<IntPair<V, Easing>>,
    durationMillis: Int,
    delayMillis: Int
)
Cmn

Public functions

open V
getValueFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
)
Cmn
open 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

open Int

delay defines the amount of time that animation can be delayed.

Cmn
open Int

duration is the amount of time while animation is not yet finished.

Cmn

Inherited functions

From androidx.compose.animation.core.VectorizedAnimationSpec
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
From androidx.compose.animation.core.VectorizedDurationBasedAnimationSpec
open Long
getDurationNanos(initialValue: V, targetValue: V, initialVelocity: V)

Calculates the duration of an animation.

Cmn

Inherited properties

From androidx.compose.animation.core.VectorizedFiniteAnimationSpec
open Boolean

Whether or not the VectorizedAnimationSpec specifies an infinite animation.

Cmn

Public constructors

VectorizedKeyframesSpec

<V : AnimationVector> VectorizedKeyframesSpec(
    keyframes: Map<IntPair<V, Easing>>,
    durationMillis: Int,
    delayMillis: Int = 0
)
Parameters
keyframes: Map<IntPair<V, Easing>>

a map from time to a value/easing function pair. The value in each entry defines the animation value at that time, and the easing curve is used in the interval starting from that time.

durationMillis: Int

total duration of the animation

delayMillis: Int = 0

the amount of the time the animation should wait before it starts. Defaults to 0.

Public functions

getValueFromNanos

open fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: V,
    targetValue: V,
    initialVelocity: V
): V
Throws
kotlin.IllegalStateException

When the initial or final value to animate within a keyframe is missing.

getVelocityFromNanos

open 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

delayMillis

open val delayMillisInt

delay defines the amount of time that animation can be delayed.

durationMillis

open val durationMillisInt

duration is the amount of time while animation is not yet finished.