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 com.jakewharton.mosaic.animation.Animatable and com.jakewharton.mosaic.animation.Transition. Consider using those APIs for the interruption handling, as well as built-in animation lifecycle management.

Parameters

animationSpec

the com.jakewharton.mosaic.animation.VectorizedAnimationSpec that will be used to calculate value/velocity

initialValue

the start value of the animation

targetValue

the end value of the animation

typeConverter

the com.jakewharton.mosaic.animation.TwoWayConverter that is used to convert animation type T from/to V

initialVelocityVector

the start velocity of the animation in the form of AnimationVector

See also

Constructors

Link copied to clipboard
constructor(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.

Properties

Link copied to clipboard
open override val durationNanos: Long

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

Link copied to clipboard
Link copied to clipboard
open override 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.

Link copied to clipboard
open override val targetValue: T

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

Link copied to clipboard
open override val typeConverter: TwoWayConverter<T, V>

Functions

Link copied to clipboard
open override fun getValueFromNanos(playTimeNanos: Long): T

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

Link copied to clipboard
fun <T, V : AnimationVector> Animation<T, V>.getVelocityFromNanos(playTimeNanos: Long): T

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

Link copied to clipboard
open override fun getVelocityVectorFromNanos(playTimeNanos: Long): V

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

Link copied to clipboard
open fun isFinishedFromNanos(playTimeNanos: Long): Boolean

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

Link copied to clipboard
open override fun toString(): String