Composable Function

AnimatedSpatialVisibility

AnimatedSpatialVisibility composable animates the appearance and disappearance of its subspace content, as visible value changes.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free

AnimatedSpatialVisibility

Android
@Composable
@SubspaceComposable
public fun AnimatedSpatialVisibility(
    visible: Boolean,
    modifier: SubspaceModifier = SubspaceModifier,
    enter: SpatialEnterTransition = SpatialTransitionDefaults.DefaultEnter,
    exit: SpatialExitTransition = SpatialTransitionDefaults.DefaultExit,
    label: String = "AnimatedSpatialVisibility",
    content: @Composable @SubspaceComposable AnimatedSpatialVisibilityScope.() -> Unit,
)

AnimatedSpatialVisibility composable animates the appearance and disappearance of its subspace content, as visible value changes. Different SpatialEnterTransitions and SpatialExitTransitions can be defined in enter and exit for the appearance and disappearance animation. There are 4 types of SpatialEnterTransition and [SpatialExitTransition]: Fade, Expand/Shrink, Scale and Slide. The enter transitions can be combined using +. Same for exit transitions. The order of the combination does not matter, as the transition animations will start simultaneously. See SpatialEnterTransition and SpatialExitTransition for details on the three types of transition.

Parameters

visible defines whether the content should be visible
modifier modifier for the SubspaceLayout created to contain the content
enter EnterTransition(s) used for the appearing animation
exit ExitTransition(s) used for the disappearing animation
label A label to differentiate from other animations in Android Studio animation preview.
content Content to appear or disappear based on the value of visible

AnimatedSpatialVisibility

Android
@Composable
@SubspaceComposable
public fun AnimatedSpatialVisibility(
    visibleState: MutableTransitionState<Boolean>,
    modifier: SubspaceModifier = SubspaceModifier,
    enter: SpatialEnterTransition = SpatialTransitionDefaults.DefaultEnter,
    exit: SpatialExitTransition = SpatialTransitionDefaults.DefaultExit,
    label: String = "AnimatedSpatialVisibility",
    content: @Composable @SubspaceComposable AnimatedSpatialVisibilityScope.() -> Unit,
)

AnimatedSpatialVisibility composable animates the appearance and disappearance of its content, as visibleState's targetState changes. The visibleState can also be used to observe the state of AnimatedSpatialVisibility. For example: visibleState.isIdle indicates whether all the animations have finished in AnimatedSpatialVisibility, and visibleState.currentState returns the initial state of the current animations.

Parameters

visibleState defines whether the content should be visible
modifier modifier for the SubspaceLayout created to contain the content
enter EnterTransition(s) used for the appearing animation
exit ExitTransition(s) used for the disappearing animation
label A label to differentiate from other animations in Android Studio animation preview.
content Content to appear or disappear based on the value of visibleState

AnimatedSpatialVisibility

Android
@Composable
@SubspaceComposable
public fun <T> Transition<T>.AnimatedSpatialVisibility(
    visible: (T) -> Boolean,
    modifier: SubspaceModifier = SubspaceModifier,
    enter: SpatialEnterTransition = SpatialTransitionDefaults.DefaultEnter,
    exit: SpatialExitTransition = SpatialTransitionDefaults.DefaultExit,
    content: @Composable @SubspaceComposable AnimatedSpatialVisibilityScope.() -> Unit,
)

This extension function creates an AnimatedSpatialVisibility composable as a child Transition of the given Transition. This means: 1) the enter/exit transition is now triggered by the provided Transition's targetState change. When the targetState changes, the visibility will be derived using the visible lambda and Transition.targetState. 2) The enter/exit transitions, as well as any custom enter/exit animations defined in AnimatedSpatialVisibility are now hoisted to the parent Transition. The parent Transition will wait for all of them to finish before it considers itself finished (i.e. Transition.currentState = Transition.targetState), and subsequently removes the content in the exit case.

Parameters

visible defines whether the content should be visible based on transition state T
modifier modifier for the SubspaceLayout created to contain the content
enter EnterTransition(s) used for the appearing animation
exit ExitTransition(s) used for the disappearing animation
content Content to appear or disappear based on the visibility derived from the Transition.targetState and the provided visible lambda