Class

AnimationScope

AnimationScope provides all the animation related info specific to an animation run.

Source set: Common
public class AnimationScope<T, V : AnimationVector>
internal constructor(
    initialValue: T,
    /** [TwoWayConverter] to convert type [T] from and to [AnimationVector]. */
    public val typeConverter: TwoWayConverter<T, V>,
    initialVelocityVector: V,
    lastFrameTimeNanos: Long,
    /** Target value of the animation. */
    public val targetValue: T,
    /** Start time of the animation in the [System.nanoTime] timebase. */
    @get:Suppress("MethodNameUnits") public val startTimeNanos: Long,
    isRunning: Boolean,
    private val onCancel: () -> Unit,
)

AnimationScope provides all the animation related info specific to an animation run. An AnimationScope will be accessible during an animation.

Properties

value

Source set: Common
public var value: T

Current value of the AnimationScope.

velocityVector

Source set: Common
public var velocityVector: V

Current velocity vector of the AnimationScope.

lastFrameTimeNanos

Source set: Common
public var : Long

Last frame time of the animation.

If the animation has never started, this will be AnimationConstants.UnspecifiedTime, unless specified otherwise in the AnimationState constructor. lastFrameTimeNanos is the frame time when the animation is last updated, in the System.nanoTime timebase. It is also used for starting a sequential animation in AnimationState.animateTo. This allows the sequential animation to set its start time to when the previous animation is interrupted or finished.

finishedTimeNanos

Source set: Common
public var finishedTimeNanos: Long

The time when the animation finished successfully in the System.nanoTime timebase.

If the animation has never finished (i.e. currently running, interrupted, or never started), this will be AnimationConstants.UnspecifiedTime, unless specified otherwise in AnimationState constructor.

isRunning

Source set: Common
public var isRunning: Boolean

Indicates whether the animation is currently running.

velocity

Source set: Common
public val velocity: T

Velocity of type T, converted from velocityVector.

Functions

cancelAnimation

public fun cancelAnimation()

Cancels the animation that this AnimationScope corresponds to. The scope will not be updated any more after cancelAnimation is called.

toAnimationState

public fun toAnimationState(): AnimationState<T, V>

Creates an AnimationState that populates all the fields in AnimationState from AnimationScope.

Last updated: