shrinkOut

Function

Common
public fun shrinkOut(
    animationSpec: FiniteAnimationSpec<IntSize> =
        spring(
            stiffness = Spring.StiffnessMediumLow,
            visibilityThreshold = IntSize.VisibilityThreshold,
        ),
    shrinkTowards: Alignment = Alignment.BottomEnd,
    clip: Boolean = true,
    targetSize: (fullSize: IntSize) -> IntSize = { IntSize(0, 0) },
): ExitTransition

This shrinks the clip bounds of the disappearing content from the full size to the size returned from targetSize. shrinkTowards controls the direction of the bounds shrink animation. By default, the clip bounds animates from full size to IntSize(0, 0), shrinking towards the the bottom right corner (or bottom left corner in RTL layouts) of the content.

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

targetSize is a lambda that takes the full size of the content and returns a target size of the bounds of the content. This allows not only absolute size, but also a target 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 shrinking only horizontally or vertically, consider shrinkHorizontally, shrinkVertically.

Parameters

animationSpecthe animation used for the shrinking animation, spring by default.
shrinkTowardsthe ending point of the shrinking bounds, Alignment.BottomEnd by default.
clipwhether the content outside of the animated bounds should be clipped, true by default
targetSizereturns the end size of the shrinking bounds, 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))
    }
}