animateSizeAsState

Functions summary

State<Size>
@Composable
animateSizeAsState(
    targetValue: Size,
    animationSpec: AnimationSpec<Size>,
    label: String,
    finishedListener: ((Size) -> Unit)?
)

Fire-and-forget animation function for Size.

Cmn

Functions

animateSizeAsState

@Composable
fun animateSizeAsState(
    targetValue: Size,
    animationSpec: AnimationSpec<Size> = sizeDefaultSpring,
    label: String = "SizeAnimation",
    finishedListener: ((Size) -> Unit)? = null
): State<Size>

Fire-and-forget animation function for Size. This Composable function is overloaded for different parameter types such as Dp, Color, Offset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

animateSizeAsState returns a State object. The value of the state object will continuously be updated by the animation until the animation finishes.

Note, animateSizeAsState cannot be canceled/stopped without removing this composable function from the tree. See Animatable for cancelable animations.

val size: Size by animateSizeAsState(
    if (selected) Size(20f, 20f) else Size(10f, 10f))
Parameters
targetValue: Size

Target value of the animation

animationSpec: AnimationSpec<Size> = sizeDefaultSpring

The animation that will be used to change the value through time. Physics animation will be used by default.

label: String = "SizeAnimation"

An optional label to differentiate from other animations in Android Studio.

finishedListener: ((Size) -> Unit)? = null

An optional end listener to get notified when the animation is finished.

Returns
State<Size>

A State object, the value of which is updated by animation.