🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

KeyframesSpec

KeyframesSpec creates a VectorizedKeyframesSpec animation.

Source set: Common
public class KeyframesSpec<T>(public val config: KeyframesSpecConfig<T>) :
    DurationBasedAnimationSpec<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.

For each interval, you may provide a custom Easing by use of the KeyframesSpecConfig.using function.

By default, values are animated linearly from one interval to the next (similar to tween), however for 2-dimensional values you may animate them using arcs of quarter of an Ellipse with KeyframesSpecConfig.using and ArcMode:

If instead, you wish to have a smooth curvy animation across all intervals, consider using KeyframesWithSplineSpec.

Functions

vectorize

Source set: Common
override fun <V : AnimationVector> vectorize(
        converter: TwoWayConverter<T, V>
    ): VectorizedKeyframesSpec<V>

Members

KeyframesSpecConfig

Source set: Common
public class KeyframesSpecConfig<T> : KeyframesSpecBaseConfig<T, KeyframeEntity<T>>()

KeyframesSpecConfig stores a mutable configuration of the key frames, including durationMillis, delayMillis, and all the key frames. Each key frame defines what the animation value should be at a particular time. Once the key frames are fully configured, the KeyframesSpecConfig can be used to create a KeyframesSpec.

Functions

createEntityFor

Source set: Common
override fun createEntityFor(value: T): KeyframeEntity<T>

at

Source set: Common
override infix fun T.at(@IntRange(from = 0) timeStamp: Int): KeyframeEntity<T>

Adds a keyframe so that animation value will be this at time: timeStamp. For example: 0.8f at 150 // ms

Parameters

timeStamp The time in the during when animation should reach value: this, with a minimum value of 0.

Return

an KeyframeEntity so a custom Easing can be added by with method.

atFraction

Source set: Common
override infix fun T.atFraction(
            @FloatRange(from = 0.0, to = 1.0) fraction: Float
        ): KeyframeEntity<T>

Adds a keyframe so that the animation value will be the value specified at a fraction of the total durationMillis set. For example: 0.8f atFraction 0.50f // half of the overall duration set

Parameters

fraction The fraction when the animation should reach specified value.

Return

an KeyframeEntity so a custom Easing can be added by with method

with

Source set: Common
@Deprecated(
            message =
                "Use version that returns an instance of the entity so it can be re-used" +
                    " in other keyframe builders.",
            replaceWith = ReplaceWith("this using easing"), // Expected usage pattern
        )
        public infix fun KeyframeEntity<T>.with(easing: Easing)

Adds an Easing for the interval started with the just provided timestamp. For example: 0f at 50 with LinearEasing

Parameters

easing Easing to be used for the next interval.

Return

the same KeyframeEntity instance so that other implementations can expand on the builder pattern

using

Source set: Common
public infix fun KeyframeEntity<T>.using(arcMode: ArcMode): KeyframeEntity<T>

ArcMode applied from this keyframe to the next.

Note that arc modes are meant for objects with even dimensions (such as Offset and its variants). Where each value pair is animated as an arc. So, if the object has odd dimensions the last value will always animate linearly.

&nbsp;

The order of each value in an object with multiple dimensions is given by the applied vector converter in KeyframesSpec.vectorize.

E.g.: RectToVector assigns its values as `left, top, right, bottom so the pairs of dimensions animated as arcs are: left, top and right, bottom`.

KeyframeEntity

Source set: Common
public class KeyframeEntity<T> internal constructor(
        value: T,
        easing: Easing = LinearEasing,
        internal var arcMode: ArcMode = ArcMode.ArcLinear,
    ) : KeyframeBaseEntity<T>(value = value, easing = easing)

Holder class for building a keyframes animation.

Functions

equals

Source set: Common
override fun equals(other: Any?): Boolean

hashCode

Source set: Common
override fun hashCode(): Int