Function

shrinkVertically

This shrinks the clip bounds of the disappearing content vertically, from the full height to the height returned from targetHeight.

ExpandShrinkVerticallySample

@Sampled
@Composable
fun ExpandShrinkVerticallySample() {
    var visible by remember { mutableStateOf(true) }

    AnimatedVisibility(
        visible,
        // Sets the initial height of the content to 20, revealing only the top of the content at
        // the beginning of the expanding animation.
        enter = expandVertically(expandFrom = Alignment.Top) { 20 },
        // Shrinks the content to half of its full height via an animation.
        exit = shrinkVertically(animationSpec = tween()) { fullHeight -> fullHeight / 2 },
    ) {
        // Content that needs to appear/disappear goes here:
        Text("Content to appear/disappear", Modifier.fillMaxWidth().requiredHeight(200.dp))
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: