TargetBasedAnimation


This is a convenient animation wrapper class that works for all target based animations, i.e. animations that has a pre-defined end value, unlike decay.

It assumes that the starting value and velocity, as well as ending value do not change throughout the animation, and cache these values. This caching enables much more convenient query for animation value and velocity (where only playtime needs to be passed into the methods).

Note: When interruptions happen to the TargetBasedAnimation, a new instance should be created that use the current value and velocity as the starting conditions. This type of interruption handling is the default behavior for both Animatable and Transition. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Summary

Public constructors

<T : Any?, V : AnimationVector> TargetBasedAnimation(
    animationSpec: AnimationSpec<T>,
    typeConverter: TwoWayConverter<T, V>,
    initialValue: T,
    targetValue: T,
    initialVelocityVector: V?
)

Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.

Cmn

Public functions

open T
getValueFromNanos(playTimeNanos: Long)

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

Cmn
open V

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

Cmn
open String
Cmn

Public properties

open Long

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

Cmn
T
Cmn
open Boolean

Whether or not the Animation represents an infinite animation.

Cmn
open T

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

Cmn
open TwoWayConverter<T, V>

the TwoWayConverter that is used to convert animation type T from/to V

Cmn

Inherited functions

From androidx.compose.animation.core.Animation
open Boolean
isFinishedFromNanos(playTimeNanos: Long)

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

Cmn

Public constructors

TargetBasedAnimation

<T : Any?, V : AnimationVector> TargetBasedAnimation(
    animationSpec: AnimationSpec<T>,
    typeConverter: TwoWayConverter<T, V>,
    initialValue: T,
    targetValue: T,
    initialVelocityVector: V? = null
)

Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.

The resulting Animation assumes that the start value and velocity, as well as end value do not change throughout the animation, and cache these values. This caching enables much more convenient query for animation value and velocity (where only playtime needs to be passed into the methods).

Note: When interruptions happen to the TargetBasedAnimation, a new instance should be created that use the current value and velocity as the starting conditions. This type of interruption handling is the default behavior for both Animatable and Transition. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Parameters
animationSpec: AnimationSpec<T>

the AnimationSpec that will be used to calculate value/velocity

typeConverter: TwoWayConverter<T, V>

the TwoWayConverter that is used to convert animation type T from/to V

initialValue: T

the start value of the animation

targetValue: T

the end value of the animation

initialVelocityVector: V? = null

the start velocity vector, null by default (meaning 0 velocity).

Public functions

getValueFromNanos

open fun getValueFromNanos(playTimeNanos: Long): T

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

Parameters
playTimeNanos: Long

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

getVelocityVectorFromNanos

open fun getVelocityVectorFromNanos(playTimeNanos: Long): V

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

Parameters
playTimeNanos: Long

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

toString

open fun toString(): String

Public properties

durationNanos

open val durationNanosLong

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

initialValue

val initialValue: T

isInfinite

open val isInfiniteBoolean

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.

targetValue

open val targetValue: T

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

typeConverter

open val typeConverterTwoWayConverter<T, V>

the TwoWayConverter that is used to convert animation type T from/to V