Function

veilOut

This animates a veiling scrim over the content as it exits.

AnimatedContentVeil

@Sampled
@Composable
fun AnimatedContentVeil() {
    var visible by remember { mutableStateOf(true) }
    Column {
        Button(onClick = { visible = !visible }) { Text("Toggle") }
        AnimatedContent(
            targetState = visible,
            transitionSpec = {
                if (targetState) {
                    (slideInHorizontally { it } togetherWith veilOut()).apply {
                        targetContentZIndex = 1f
                    }
                } else {
                    unveilIn() togetherWith slideOutHorizontally { it }
                }
            },
        ) { isVisible ->
            if (isVisible) {
                Text(modifier = Modifier.fillMaxSize().background(Color.Red), text = "Page 2")
            } else {
                Text(modifier = Modifier.fillMaxSize(), text = "Page 1")
            }
        }
    }
}

AnimatedVisibilityVeil

@Sampled
@Composable
fun AnimatedVisibilityVeil() {
    var visible by remember { mutableStateOf(true) }
    Column(modifier = Modifier.background(Color.White)) {
        Button(onClick = { visible = !visible }) { Text("Toggle") }
        AnimatedVisibility(
            visible = visible,
            enter = unveilIn(initialColor = Color.White),
            exit = veilOut(targetColor = Color.White),
        ) {
            Box(Modifier.fillMaxSize().padding(30.dp).background(Color.Blue)) { Text("Content") }
        }
    }
}
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: