by @alexstyl
✉️ Leave your feedback

← Back to Compose Animation

animateContentSize

Modifier
in
Compose Animation
. Since 0.1.0-dev16

Overview

Examples

Community Notes

Video

This modifier animates its own size when its child modifier (or the child composable if it is already at the tail of the chain) changes size. This allows the parent modifier to observe a smooth size change, resulting in an overall continuous visual change.

A FiniteAnimationSpec can be optionally specified for the size change animation. By default, spring will be used.

An optional finishedListener can be supplied to get notified when the size change animation is finished. Since the content size change can be dynamic in many cases, both initial value and target value (i.e. final size) will be passed to the finishedListener. Note: if the animation is interrupted, the initial value will be the size at the point of interruption. This is intended to help determine the direction of the size change (i.e. expand or collapse in x and y dimensions).

Overloads

animateContentSize

fun Modifier.animateContentSize(
    animationSpec: FiniteAnimationSpec<IntSize> = spring(
        stiffness = Spring.StiffnessMediumLow
    ),
    finishedListener: ((initialValue: IntSize, targetValue: IntSize) -> Unit)? = null
)

Parameters

NameDescription
animationSpeca finite animation that will be used to animate size change, spring by default
finishedListeneran optional listener to be called when the content change animation is completed
Next ComponentAnimatedContent