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

TargetBasedAnimation

class TargetBasedAnimation<T, V : AnimationVector> : Animation<T, V>
kotlin.Any
   ↳ androidx.compose.animation.core.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
<init>(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.

Public methods
T
getValueFromNanos(playTimeNanos: Long)

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

V

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

Inherited functions
Inherited extension functions
From androidx.compose.animation.core
T
Animation<T, V>.getVelocityFromNanos(playTimeNanos: Long)

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

Properties
Long

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

T

the start value of the animation

Boolean

Whether or not the Animation represents an infinite animation.

T

the end value of the animation

TwoWayConverter<T, V>

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

Public constructors

<init>

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