Function

expandVertically

This expands the clip bounds of the appearing content vertically, from the height returned from initialHeight to the full height.

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: