expandIn

Function

Common
public fun expandIn(
    animationSpec: FiniteAnimationSpec<IntSize> =
        spring(
            stiffness = Spring.StiffnessMediumLow,
            visibilityThreshold = IntSize.VisibilityThreshold,
        ),
    expandFrom: Alignment = Alignment.BottomEnd,
    clip: Boolean = true,
    initialSize: (fullSize: IntSize) -> IntSize = { IntSize(0, 0) },
): EnterTransition

This expands the clip bounds of the appearing content from the size returned from initialSize to the full size. expandFrom controls which part of the content gets revealed first. By default, the clip bounds animates from IntSize(0, 0) to full size, starting from revealing the bottom right corner (or bottom left corner in RTL layouts) of the content, to fully revealing the entire content as the size expands.

Note: expandIn animates the bounds of the content. This bounds change will also result in the animation of other layouts that are dependent on this size.

initialSize is a lambda that takes the full size of the content and returns an initial size of the bounds of the content. This allows not only absolute size, but also an initial size that is proportional to the content size.

clip defines whether the content outside of the animated bounds should be clipped. By default, clip is set to true, which only shows content in the animated bounds.

For expanding only horizontally or vertically, consider expandHorizontally, expandVertically.

Parameters

animationSpecthe animation used for the expanding animation, spring by default.
expandFromthe starting point of the expanding bounds, Alignment.BottomEnd by default.
clipwhether the content outside of the animated bounds should be clipped, true by default
initialSizethe start size of the expanding bounds, returning IntSize(0, 0) by default.

Code Examples

ExpandInShrinkOutSample

@Composable
fun ExpandInShrinkOutSample() {
    var visible by remember { mutableStateOf(true) }
    AnimatedVisibility(
        visible,
        enter =
            expandIn(
                // Overwrites the default spring animation with tween
                animationSpec = tween(100, easing = LinearOutSlowInEasing),
                // Overwrites the corner of the content that is first revealed
                expandFrom = Alignment.BottomStart,
            ) {
                // Overwrites the initial size to 50 pixels by 50 pixels
                IntSize(50, 50)
            },
        exit =
            shrinkOut(
                tween(100, easing = FastOutSlowInEasing),
                // Overwrites the area of the content that the shrink animation will end on. The
                // following parameters will shrink the content's clip bounds from the full size of
                // the
                // content to 1/10 of the width and 1/5 of the height. The shrinking clip bounds
                // will
                // always be aligned to the CenterStart of the full-content bounds.
                shrinkTowards = Alignment.CenterStart,
            ) { fullSize ->
                // Overwrites the target size of the shrinking animation.
                IntSize(fullSize.width / 10, fullSize.height / 5)
            },
    ) {
        // Content that needs to appear/disappear goes here:
        Text("Content to appear/disappear", Modifier.fillMaxWidth().requiredHeight(200.dp))
    }
}