The Developer Preview for Android 11 is now available; test it out and share your feedback.

BaseAnimatedValue

sealed class BaseAnimatedValue<T, V : AnimationVector>
kotlin.Any
   ↳ androidx.animation.BaseAnimatedValue

This is the base class for AnimatedValue. It contains all the functionality of AnimatedValue. It is intended to be used as a base class for the other classes (such as AnimatedFloat to build on top of.

Animations in this class allow and anticipate the animation target to change frequently. When the target changes as the animation is in-flight, the animation is expected to make a continuous transition to the new target.

Summary

Public methods

Unit
animateTo(targetValue: T)

Sets the target value, which effectively starts an animation to change the value from value to the target value.

Unit
animateTo(targetValue: T, onEnd: (AnimationEndReason, T) -> Unit)

Sets the target value, which effectively starts an animation to change the value from value to the target value.

Unit
animateTo(targetValue: T, anim: AnimationBuilder<T>, onEnd: (AnimationEndReason, T) -> Unit)

Sets the target value, which effectively starts an animation to change the value from value to the target value.

Unit
animateTo(targetValue: T, anim: AnimationBuilder<T>)

Sets the target value, which effectively starts an animation to change the value from value to the target value.

open Unit
snapTo(targetValue: T)

Sets the current value to the target value immediately, without any animation.

Unit

Stops any on-going animation.

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

Boolean

Indicates whether the animation is running.

T

The target of the current animation.

T

Current value of the animation.

Public methods

animateTo

fun animateTo(targetValue: T): Unit

Sets the target value, which effectively starts an animation to change the value from value to the target value. If there is already an animation in flight, this method will interrupt the ongoing animation, and start a new animation from the current value to the new target value.

Parameters
targetValue: T The new value to animate to

animateTo

fun animateTo(
    targetValue: T,
    onEnd: (AnimationEndReason, T) -> Unit
): Unit

Sets the target value, which effectively starts an animation to change the value from value to the target value. If there is already an animation in flight, this method will interrupt the ongoing animation, invoke onEnd that is associated with that animation, and start a new animation from the current value to the new target value.

Parameters
targetValue: T The new value to animate to
onEnd: (AnimationEndReason, T) -> Unit A callback that will be invoked when the animation finished by any reason.

animateTo

fun animateTo(
    targetValue: T,
    anim: AnimationBuilder<T>,
    onEnd: (AnimationEndReason, T) -> Unit
): Unit

Sets the target value, which effectively starts an animation to change the value from value to the target value. If there is already an animation in flight, this method will interrupt the ongoing animation, invoke onEnd that is associated with that animation, and start a new animation from the current value to the new target value.

Parameters
targetValue: T The new value to animate to
anim: AnimationBuilder<T> The animation that will be used to animate from the current value to the new target value
onEnd: (AnimationEndReason, T) -> Unit A callback that will be invoked when the animation finished by any reason.

animateTo

fun animateTo(
    targetValue: T,
    anim: AnimationBuilder<T>
): Unit

Sets the target value, which effectively starts an animation to change the value from value to the target value. If there is already an animation in flight, this method will interrupt the ongoing animation, invoke onEnd that is associated with that animation, and start a new animation from the current value to the new target value.

Parameters
targetValue: T The new value to animate to
anim: AnimationBuilder<T> The animation that will be used to animate from the current value to the new target value

snapTo

open fun snapTo(targetValue: T): Unit

Sets the current value to the target value immediately, without any animation.

Parameters
targetValue: T The new target value to set value to.

stop

fun stop(): Unit

Stops any on-going animation. No op if no animation is running. Note that this method does not skip the animation value to its target value. Rather the animation will be stopped in its track.

Properties

isRunning

var isRunning: Boolean

Indicates whether the animation is running.

targetValue

var targetValue: T

The target of the current animation. This target will not be the same as the value of the animation, until the animation finishes un-interrupted.

value

var value: T

Current value of the animation.