( 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.' /> ( 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.'>

VectorizedKeyframesSpec

Class

Common
public class VectorizedKeyframesSpec<V : AnimationVector>
internal constructor(
    private val timestamps: IntList,
    private val keyframes: IntObjectMap<VectorizedKeyframeSpecElementInfo<V>>,
    override val durationMillis: Int,
    override val delayMillis: Int,
    private val defaultEasing: Easing,
    private val initialArcMode: ArcMode,
) : VectorizedDurationBasedAnimationSpec<V>

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.

Secondary Constructors

public constructor(
    keyframes: Map<Int, Pair<V, Easing>>,
    durationMillis: Int,
    delayMillis: Int = 0,
) : this(
    timestamps =
        kotlin.run {
            val times = MutableIntList(keyframes.size + 2)
            keyframes.forEach { (t, _) -> times.add(t) }
            if (!keyframes.containsKey(0)) {
                times.add(0, 0)
            }
            if (!keyframes.containsKey(durationMillis)) {
                times.add(durationMillis)
            }
            times.sort()
            return@run times
        },
    keyframes =
        kotlin.run {
            val timeToInfoMap = MutableIntObjectMap<VectorizedKeyframeSpecElementInfo<V>>()
            keyframes.forEach { (time, valueEasing) ->
                timeToInfoMap[time] =
                    VectorizedKeyframeSpecElementInfo(
                        vectorValue = valueEasing.first,
                        easing = valueEasing.second,
                        arcMode = ArcMode.ArcLinear,
                    )
            }

            return@run timeToInfoMap
        },
    durationMillis = durationMillis,
    delayMillis = delayMillis,
    defaultEasing = LinearEasing,
    initialArcMode = ArcMode.ArcLinear,
)

Parameters

keyframesa 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.
durationMillistotal duration of the animation
delayMillisthe amount of the time the animation should wait before it starts. Defaults to 0.