State of Compose 2023 results are in! Click here to learn more

← Back to Compose Animation

Crossfade

Component
in
Compose Animation
. Since 0.1.0-dev15

Overview

Code Examples

Crossfade allows to switch between two layouts with a crossfade animation.

Overloads

Crossfade

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun <T> Crossfade(
    targetState: T,
    modifier: Modifier = Modifier,
    animationSpec: FiniteAnimationSpec<Float> = tween(),
    label: String = "Crossfade",
    content: @Composable (T) -> Unit
)

Parameters

NameDescription
targetStateis a key representing your target layout state. Every time you change a key the animation will be triggered. The content called with the old key will be faded out while the content called with the new key will be faded in.
modifierModifier to be applied to the animation container.
animationSpecthe AnimationSpec to configure the animation.
labelAn optional label to differentiate from other animations in Android Studio