Google is committed to advancing racial equity for Black communities. See how.

KeyframesSpec

@Immutable class KeyframesSpec<T> : DurationBasedAnimationSpec<T>
kotlin.Any
   ↳ androidx.compose.animation.core.KeyframesSpec

KeyframesSpec creates a VectorizedKeyframesSpec animation.

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

import androidx.compose.animation.core.KeyframesSpec

KeyframesSpec(KeyframesSpec.KeyframesSpecConfig<Float>().apply {
    0f at 0 // ms  // Optional
    0.4f at 75 // ms
    0.4f at 225 // ms
    0f at 375 // ms  // Optional
    durationMillis = 375
})
You can also provide a custom Easing for the interval with use of with function appliedfor the interval starting keyframe.
import androidx.compose.animation.core.keyframes

// Use FastOutSlowInEasing for the interval from 0 to 50 ms, and LinearOutSlowInEasing for the
// time between 50 and 100ms
keyframes<Float> {
    durationMillis = 100
    0f at 0 with FastOutSlowInEasing
    1.5f at 50 with LinearOutSlowInEasing
    1f at 100
}

Summary

Nested classes

Holder class for building a keyframes animation.

KeyframesSpecConfig stores a mutable configuration of the key frames, including durationMillis, delayMillis, and all the key frames.

Public constructors

KeyframesSpec creates a VectorizedKeyframesSpec animation.

Public methods
VectorizedKeyframesSpec<V>
vectorize(converter: TwoWayConverter<T, V>)

Creates a VectorizedAnimationSpec with the given TwoWayConverter.

Properties
KeyframesSpec.KeyframesSpecConfig<T>

Public constructors

<init>

KeyframesSpec(config: KeyframesSpec.KeyframesSpecConfig<T>)

KeyframesSpec creates a VectorizedKeyframesSpec animation.

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

import androidx.compose.animation.core.KeyframesSpec

KeyframesSpec(KeyframesSpec.KeyframesSpecConfig<Float>().apply {
    0f at 0 // ms  // Optional
    0.4f at 75 // ms
    0.4f at 225 // ms
    0f at 375 // ms  // Optional
    durationMillis = 375
})
You can also provide a custom Easing for the interval with use of with function appliedfor the interval starting keyframe.
import androidx.compose.animation.core.keyframes

// Use FastOutSlowInEasing for the interval from 0 to 50 ms, and LinearOutSlowInEasing for the
// time between 50 and 100ms
keyframes<Float> {
    durationMillis = 100
    0f at 0 with FastOutSlowInEasing
    1.5f at 50 with LinearOutSlowInEasing
    1f at 100
}

Public methods

vectorize

fun <V : AnimationVector> vectorize(converter: TwoWayConverter<T, V>): VectorizedKeyframesSpec<V>

Creates a VectorizedAnimationSpec with the given TwoWayConverter.

The underlying animation system operates on AnimationVectors. T will be converted to AnimationVector to animate. VectorizedAnimationSpec describes how the converted AnimationVector should be animated. E.g. The animation could simply interpolate between the start and end values (i.e.TweenSpec), or apply spring physics to produce the motion (i.e. SpringSpec), etc)

Parameters
converter: TwoWayConverter<T, V> converts the type T from and to AnimationVector type

Properties

config

val config: KeyframesSpec.KeyframesSpecConfig<T>