@Composable
fun AnimatedVisibilityCookbook() {
Box(modifier = Modifier.fillMaxSize()) {
// [START android_compose_animation_cookbook_visibility]
var visible by remember {
mutableStateOf(true)
}
// Animated visibility will eventually remove the item from the composition once the animation has finished.
AnimatedVisibility(visible, enter = slideInVertically(), exit = slideOutVertically(){-it}) {
// your composable here
// [START_EXCLUDE]
Box(
modifier = Modifier
.size(200.dp)
.clip(RoundedCornerShape(8.dp))
.background(Color.Green)
) {
}
// [END_EXCLUDE]
}
// [END android_compose_animation_cookbook_visibility]
Button(modifier = Modifier.align(Alignment.BottomCenter), onClick = {
visible = !visible
}) {
Text("Show/Hide")
}
}
}