fadeOut
Function
Common
public fun fadeOut(
animationSpec: FiniteAnimationSpec<Float> = spring(stiffness = Spring.StiffnessMediumLow),
targetAlpha: Float = 0f,
): ExitTransition
This fades out the content of the transition, from full opacity to the specified target alpha
(i.e. targetAlpha
), using the supplied animationSpec
. By default, the content will be faded
out to fully transparent (i.e. targetAlpha
defaults to 0), and animationSpec
uses spring
by
default.
Parameters
animationSpec | the FiniteAnimationSpec for this animation, spring by default |
targetAlpha | the target alpha of the exit transition, 0f by default |
Code Examples
FadeTransition
@Composable
fun FadeTransition() {
var visible by remember { mutableStateOf(true) }
AnimatedVisibility(
visible = visible,
enter =
fadeIn(
// Overwrites the initial value of alpha to 0.4f for fade in, 0 by default
initialAlpha = 0.4f
),
exit =
fadeOut(
// Overwrites the default animation with tween
animationSpec = tween(durationMillis = 250)
),
) {
// Content that needs to appear/disappear goes here:
Text("Content to appear/disappear", Modifier.fillMaxWidth().requiredHeight(200.dp))
}
}