CapturedAnimatedVisibility
@Composable
public fun CapturedAnimatedVisibility(
visible: Boolean,
modifier: Modifier = Modifier,
enter: EnterTransition = fadeIn() + expandIn(),
exit: ExitTransition = shrinkOut() + fadeOut(),
label: String = "CapturedAnimatedVisibility",
content: @Composable () -> Unit,
)
CapturedAnimatedVisibility animates the appearance and disappearance of its content as visible changes. Unlike AnimatedVisibility, when visible becomes false the child composition is removed immediately and the exit transition animates the last captured frame of the content via a graphics layer. This means the caller does not need to retain any data for the content once visible is false.
CapturedAnimatedVisibility is designed for content removal animations where there is a need to immediately release resources or a desire to no longer maintain data or states during exit. Since CapturedAnimatedVisibility displays a layer that captured the rendering of the content, it will also not respond to any gestures. In contrast, content in AnimatedVisibility remains live in composition during exit, responding to touch input and continuing internal animations (e.g. shared element or infinite animations) until the exit animation finishes and the content is removed from composition.
Because the content is no longer live during exit, no AnimatedVisibilityScope is provided to the content lambda.
Parameters
| visible | controls whether the content should be visible |
| modifier | Modifier for the layout |
| enter | EnterTransition used for the appearing animation |
| exit | ExitTransition applied to the last captured frame when disappearing |
| label | label to differentiate from other animations in Android Studio Animation Preview |
| content | content to appear or disappear based on visible |
CapturedAnimatedVisibility
@Composable
public fun CapturedAnimatedVisibility(
visibleState: MutableTransitionState<Boolean>,
modifier: Modifier = Modifier,
enter: EnterTransition = fadeIn() + expandIn(),
exit: ExitTransition = shrinkOut() + fadeOut(),
label: String = "CapturedAnimatedVisibility",
content: @Composable () -> Unit,
)
Animates the appearance and disappearance of its content as visibleState's target state changes.
Using a MutableTransitionState allows observing the state of the animation (e.g. MutableTransitionState.currentState, * MutableTransitionState.targetState, and MutableTransitionState.isIdle) as well as setting an initial visibility state that is different than the MutableTransitionState.targetState to animate content upon entering composition.
Unlike AnimatedVisibility, when visibleState's targetState becomes false the child composition is removed immediately in CapturedAnimatedVisibility. The exit transition animates the last captured frame of the content via a graphics layer.
Parameters
| visibleState | MutableTransitionState controlling visibility and allowing animation state observation |
| modifier | Modifier for the layout |
| enter | EnterTransition used for the appearing animation |
| exit | ExitTransition applied to the last captured frame when disappearing |
| label | label to differentiate from other animations in Android Studio Animation Preview |
| content | content to appear or disappear based on visibleState |