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

DecayAnimationSpec

public interface DecayAnimationSpec<T extends Object>


DecayAnimationSpec stores the specification of an animation, including 1) the data type to be animated, and 2) the animation configuration (i.e. VectorizedDecayAnimationSpec) that will be used once the data (of type T) has been converted to AnimationVector.

Any type T can be animated by the system as long as a TwoWayConverter is supplied to convert the data type T from and to an AnimationVector. There are a number of converters available out of the box. For example, to animate androidx.compose.ui.unit.IntOffset the system uses IntOffset.VectorConverter to convert the object to AnimationVector2D, so that both x and y dimensions are animated independently with separate velocity tracking. This enables multidimensional objects to be animated in a true multi-dimensional way. It is particularly useful for smoothly handling animation interruptions (such as when the target changes during the animation).

Summary

Public methods

abstract @NonNull VectorizedDecayAnimationSpec<@NonNull V>
<V extends AnimationVector> vectorize(
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter
)

Creates a VectorizedDecayAnimationSpec with the given TwoWayConverter.

Extension functions

default final float
DecayAnimationSpecKt.calculateTargetValue(
    @NonNull DecayAnimationSpec<@NonNull Float> receiver,
    float initialValue,
    float initialVelocity
)

Calculates the target value of a Float decay animation based on the initialValue and initialVelocity.

default final @NonNull T
<T extends Object, V extends AnimationVector> DecayAnimationSpecKt.calculateTargetValue(
    @NonNull DecayAnimationSpec<@NonNull T> receiver,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull T initialVelocity
)

Calculates the target value of a decay animation based on the initialValue and initialVelocity, and the typeConverter that converts the given type T to AnimationVector.

Public methods

vectorize

abstract @NonNull VectorizedDecayAnimationSpec<@NonNull V> <V extends AnimationVector> vectorize(
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter
)

Creates a VectorizedDecayAnimationSpec with the given TwoWayConverter.

The underlying animation system operates on AnimationVectors. T will be converted to AnimationVector to animate. VectorizedDecayAnimationSpec describes how the converted AnimationVector should be animated.

Parameters
@NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter

converts the type T from and to AnimationVector type

Extension functions

DecayAnimationSpecKt.calculateTargetValue

default final float DecayAnimationSpecKt.calculateTargetValue(
    @NonNull DecayAnimationSpec<@NonNull Float> receiver,
    float initialValue,
    float initialVelocity
)

Calculates the target value of a Float decay animation based on the initialValue and initialVelocity.

Returns
float

target value where the animation will come to a natural stop

DecayAnimationSpecKt.calculateTargetValue

default final @NonNull T <T extends Object, V extends AnimationVector> DecayAnimationSpecKt.calculateTargetValue(
    @NonNull DecayAnimationSpec<@NonNull T> receiver,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull T initialVelocity
)

Calculates the target value of a decay animation based on the initialValue and initialVelocity, and the typeConverter that converts the given type T to AnimationVector.

Returns
@NonNull T

target value where the animation will come to a natural stop