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

FloatDecayAnimationSpec

interface FloatDecayAnimationSpec
androidx.compose.animation.core.FloatDecayAnimationSpec

This animation interface is intended to be stateless, just like Animation. But unlike Animation, DecayAnimation does not have an end value defined. The end value is a result of the animation rather than an input.

Summary

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

Returns the duration of the decay animation, in nanoseconds.

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

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

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

Returns the value of the animation at the given time.

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

Returns the velocity of the animation at the given time.

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
abstract Float

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

Public methods

getDurationNanos

abstract 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

abstract 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

abstract 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

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

Returns the velocity 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

Properties

absVelocityThreshold

abstract val absVelocityThreshold: Float

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