TargetBasedAnimation
-
Cmn
class TargetBasedAnimation<T : Any?, V : AnimationVector> : Animation
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(Creates a |
Cmn
|
Public functions |
||
|---|---|---|
open T |
getValueFromNanos(playTimeNanos: Long)Returns the value of the animation at the given play time. |
Cmn
|
open V |
getVelocityVectorFromNanos(playTimeNanos: Long)Returns the velocity (in |
Cmn
|
open String |
toString() |
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 |
Cmn
|
open T |
This is the value that the |
Cmn
|
open TwoWayConverter<T, V> |
the |
Cmn
|
Inherited functions |
|||
|---|---|---|---|
|
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 |
typeConverter: TwoWayConverter<T, V> |
the |
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. |
Public properties
durationNanos
open val durationNanos: Long
This amount of time in nanoseconds that the animation will run before it finishes
isInfinite
open val isInfinite: Boolean
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 typeConverter: TwoWayConverter<T, V>
the TwoWayConverter that is used to convert animation type T from/to V