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

DecayAnimation

public final class DecayAnimation<T extends Object, V extends AnimationVector> implements Animation


DecayAnimation is an animation that slows down from initialVelocityVector as time goes on. DecayAnimation is stateless, and it does not have any concept of lifecycle. It serves as an animation calculation engine that supports convenient query of value/velocity given a play time. To achieve that, DecayAnimation stores all the animation related information: initialValue, initialVelocityVector, decay animation spec, typeConverter.

Note: Unless there's a need to control the timing manually, it's generally recommended to use higher level animation APIs that build on top DecayAnimation, such as Animatable.animateDecay, AnimationState.animateDecay, etc.

See also
animateDecay
animateDecay

Summary

Public constructors

<T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull DecayAnimationSpec<@NonNull T> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull T initialVelocity
)

DecayAnimation is an animation that slows down from initialVelocity as time goes on.

<T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull DecayAnimationSpec<@NonNull T> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull V initialVelocityVector
)

DecayAnimation is an animation that slows down from initialVelocityVector as time goes on.

<T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull VectorizedDecayAnimationSpec<@NonNull V> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull V initialVelocityVector
)

Public methods

long

This amount of time in nanoseconds that the animation will run before it finishes

final @NonNull T
final @NonNull V
@NonNull T

This is the value that the Animation will reach when it finishes uninterrupted.

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

The TwoWayConverter that will be used to convert value/velocity from any arbitrary data type to AnimationVector.

@NonNull T
getValueFromNanos(long playTimeNanos)

Returns the value of the animation at the given play time.

@NonNull V
getVelocityVectorFromNanos(long playTimeNanos)

Returns the velocity (in AnimationVector form) of the animation at the given play time.

boolean

Whether or not the Animation represents an infinite animation.

Inherited methods

From androidx.compose.animation.core.Animation
boolean
isFinishedFromNanos(long playTimeNanos)

Returns whether the animation is finished at the given play time.

Public constructors

DecayAnimation

public <T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull DecayAnimationSpec<@NonNull T> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull T initialVelocity
)

DecayAnimation is an animation that slows down from initialVelocity as time goes on. DecayAnimation is stateless, and it does not have any concept of lifecycle. It serves as an animation calculation engine that supports convenient query of value/velocity given a play time. To achieve that, DecayAnimation stores all the animation related information: initialValue, initialVelocity, animationSpec, typeConverter.

Note: Unless there's a need to control the timing manually, it's generally recommended to use higher level animation APIs that build on top DecayAnimation, such as Animatable.animateDecay, AnimationState.animateDecay, etc.

Parameters
@NonNull DecayAnimationSpec<@NonNull T> animationSpec

Decay animation spec that defines the slow-down curve of the animation

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

Type converter to convert the type T from and to AnimationVector

@NonNull T initialValue

The starting value of the animation

@NonNull T initialVelocity

The starting velocity of the animation

DecayAnimation

public <T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull DecayAnimationSpec<@NonNull T> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull V initialVelocityVector
)

DecayAnimation is an animation that slows down from initialVelocityVector as time goes on. DecayAnimation is stateless, and it does not have any concept of lifecycle. It serves as an animation calculation engine that supports convenient query of value/velocity given a play time. To achieve that, DecayAnimation stores all the animation related information: initialValue, initialVelocityVector, decay animation spec, typeConverter.

Note: Unless there's a need to control the timing manually, it's generally recommended to use higher level animation APIs that build on top DecayAnimation, such as Animatable.animateDecay, AnimationState.animateDecay, etc.

Parameters
@NonNull DecayAnimationSpec<@NonNull T> animationSpec

Decay animation spec that defines the slow-down curve of the animation

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

Type converter to convert the type T from and to AnimationVector

@NonNull T initialValue

The starting value of the animation

@NonNull V initialVelocityVector

The starting velocity of the animation in AnimationVector form

DecayAnimation

public <T extends Object, V extends AnimationVector> DecayAnimation(
    @NonNull VectorizedDecayAnimationSpec<@NonNull V> animationSpec,
    @NonNull TwoWayConverter<@NonNull T, @NonNull V> typeConverter,
    @NonNull T initialValue,
    @NonNull V initialVelocityVector
)

Public methods

getDurationNanos

public long getDurationNanos()

This amount of time in nanoseconds that the animation will run before it finishes

getInitialValue

public final @NonNullgetInitialValue()

getInitialVelocityVector

public final @NonNullgetInitialVelocityVector()

getTargetValue

public @NonNullgetTargetValue()

This is the value that the Animation will reach when it finishes uninterrupted.

getTypeConverter

public @NonNull TwoWayConverter<@NonNull T, @NonNull V> getTypeConverter()

The TwoWayConverter that will be used to convert value/velocity from any arbitrary data type to AnimationVector. This makes it possible to animate different dimensions of the data object independently (e.g. x/y dimensions of the position data).

getValueFromNanos

public @NonNullgetValueFromNanos(long playTimeNanos)

Returns the value of the animation at the given play time.

Parameters
long playTimeNanos

the play time that is used to determine the value of the animation.

getVelocityVectorFromNanos

public @NonNullgetVelocityVectorFromNanos(long playTimeNanos)

Returns the velocity (in AnimationVector form) of the animation at the given play time.

Parameters
long playTimeNanos

the play time that is used to calculate the velocity of the animation.

isInfinite

public boolean isInfinite()

Whether or not the Animation represents an infinite animation. That is, one that will not finish by itself, one that needs an external action to stop. For examples, an indeterminate progress bar, which will only stop when it is removed from the composition.