Android 12 Developer Preview is here! Try it out, and give us your feedback!

FloatExponentialDecaySpec

class FloatExponentialDecaySpec : FloatDecayAnimationSpec
kotlin.Any
   ↳ androidx.compose.animation.core.FloatExponentialDecaySpec

This is a decay animation 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.

Summary

Public constructors
<init>(frictionMultiplier: Float = 1f, absVelocityThreshold: Float = 0.1f)

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

Public methods
Long
getDurationNanos(initialValue: Float, initialVelocity: Float)

Returns the duration of the decay animation, in nanoseconds.

Float
getTargetValue(initialValue: Float, initialVelocity: Float)

Returns the target value of the animation based on the starting condition of the animation ( i.

Float
getValueFromNanos(playTimeNanos: Long, initialValue: Float, initialVelocity: Float)

Returns the value of the animation at the given time.

Float
getVelocityFromNanos(playTimeNanos: Long, initialValue: Float, initialVelocity: Float)

Returns the velocity of the animation at the given time.

Inherited extension functions
From androidx.compose.animation.core
DecayAnimationSpec<T>

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

Properties
Float

This is the absolute value of a velocity threshold, below which the animation is considered finished.

Public constructors

<init>

FloatExponentialDecaySpec(
    frictionMultiplier: Float = 1f,
    absVelocityThreshold: Float = 0.1f)

This is a decay animation 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.

Parameters
frictionMultiplier: Float = 1f The friction multiplier, indicating how quickly the animation should stop. This should be greater than 0, with a default value of 1.0.
absVelocityThreshold: Float = 0.1f The speed at which the animation is considered close enough to rest for the animation to finish.

Public methods

getDurationNanos

fun getDurationNanos(
    initialValue: Float,
    initialVelocity: Float
): Long

Returns the duration of the decay animation, in nanoseconds.

Parameters
initialValue: Float start value of the animation
initialVelocity: Float start velocity of the animation

getTargetValue

fun getTargetValue(
    initialValue: Float,
    initialVelocity: Float
): Float

Returns the target value of the animation based on the starting condition of the animation ( i.e. start value and start velocity).

Parameters
initialValue: Float The start value of the animation
initialVelocity: Float The start velocity of the animation

getValueFromNanos

fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
): Float

Returns the value of the animation at the given time.

Parameters
playTimeNanos: Long The time elapsed in milliseconds since the start of the animation
initialValue: Float The start value of the animation
initialVelocity: Float The start velocity of the animation

getVelocityFromNanos

fun getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
): Float

Returns the velocity of the animation at the given time.

Parameters