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

DecayAnimationSpecKt

public final class DecayAnimationSpecKt


Summary

Public methods

static final float
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.

static final @NonNull T
<T extends Object, V extends AnimationVector> 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.

static final @NonNull DecayAnimationSpec<@NonNull T>
<T extends Object> exponentialDecay(
    float frictionMultiplier,
    float absVelocityThreshold
)

Creates a decay animation spec where the friction/deceleration is always proportional to the velocity.

static final @NonNull DecayAnimationSpec<@NonNull T>

Creates a DecayAnimationSpec from a FloatDecayAnimationSpec by applying the given FloatDecayAnimationSpec on every dimension of the AnimationVector that T converts to.

Public methods

calculateTargetValue

public static final float 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

calculateTargetValue

public static final @NonNull T <T extends Object, V extends AnimationVector> 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

exponentialDecay

public static final @NonNull DecayAnimationSpec<@NonNull T> <T extends Object> exponentialDecay(
    float frictionMultiplier,
    float absVelocityThreshold
)

Creates a decay animation spec where the friction/deceleration is always proportional to the velocity. As a result, the velocity goes under an exponential decay. The constructor parameter, frictionMultiplier, can be tuned to adjust the amount of friction applied in the decay. The higher the multiplier, the higher the friction, the sooner the animation will stop, and the shorter distance the animation will travel with the same starting condition. absVelocityThreshold describes the absolute value of a velocity threshold, below which the animation is considered finished.

Parameters
float frictionMultiplier

The decay friction multiplier. This must be greater than 0.

float absVelocityThreshold

The minimum speed, below which the animation is considered finished. Must be greater than 0.

generateDecayAnimationSpec

public static final @NonNull DecayAnimationSpec<@NonNull T> <T extends Object> generateDecayAnimationSpec(
    @NonNull FloatDecayAnimationSpec receiver
)

Creates a DecayAnimationSpec from a FloatDecayAnimationSpec by applying the given FloatDecayAnimationSpec on every dimension of the AnimationVector that T converts to.