{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

VectorizedKeyframesSpec

public final class VectorizedKeyframesSpec<V extends AnimationVector> implements VectorizedDurationBasedAnimationSpec


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
)
See also
KeyframesSpec

Summary

Public constructors

<V extends AnimationVector> VectorizedKeyframesSpec(
    @NonNull Map<@NonNull Integer, @NonNull Pair<@NonNull V, @NonNull Easing>> keyframes,
    int durationMillis,
    int delayMillis
)

Public methods

int

the amount of the time the animation should wait before it starts.

int

total duration of the animation

@NonNull V
getValueFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

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

@NonNull V
getVelocityFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

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

Inherited methods

From androidx.compose.animation.core.VectorizedAnimationSpec
@NonNull V
getEndVelocity(
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

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

From androidx.compose.animation.core.VectorizedDurationBasedAnimationSpec
long
getDurationNanos(
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the duration of an animation.

From androidx.compose.animation.core.VectorizedFiniteAnimationSpec
boolean

Whether or not the VectorizedAnimationSpec specifies an infinite animation.

Public constructors

VectorizedKeyframesSpec

public <V extends AnimationVector> VectorizedKeyframesSpec(
    @NonNull Map<@NonNull Integer, @NonNull Pair<@NonNull V, @NonNull Easing>> keyframes,
    int durationMillis,
    int delayMillis
)
Parameters
@NonNull Map<@NonNull Integer, @NonNull Pair<@NonNull V, @NonNull Easing>> keyframes

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.

int durationMillis

total duration of the animation

int delayMillis

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

Public methods

getDelayMillis

public int getDelayMillis()

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

getDurationMillis

public int getDurationMillis()

total duration of the animation

getValueFromNanos

public @NonNullgetValueFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

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

Parameters
long playTimeNanos

time since the start of the animation

@NonNull V initialValue

start value of the animation

@NonNull V targetValue

end value of the animation

@NonNull V initialVelocity

start velocity of the animation

getVelocityFromNanos

public @NonNullgetVelocityFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

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

Parameters
long playTimeNanos

time since the start of the animation

@NonNull V initialValue

start value of the animation

@NonNull V targetValue

end value of the animation

@NonNull V initialVelocity

start velocity of the animation