Function

shrinkVertically

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

ExpandShrinkVerticallySample

@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))
    }
}