Object

SpatialTransitions

Public transition spec APIs for use with AnimatedSpatialVisibility.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Android
public object SpatialTransitions

Public transition spec APIs for use with AnimatedSpatialVisibility.

Functions

fadeIn

public fun fadeIn(
        animationSpec: FiniteAnimationSpec<Float> =
            SpatialTransitionDefaults.DefaultAlphaAnimationSpec,
        initialAlpha: Float = 0f,
    ): SpatialEnterTransition

This fades in the content of the transition, from the specified starting alpha (i.e. initialAlpha) to 1f, using the supplied animationSpec. initialAlpha defaults to 0f, and spring is used by default.

Parameters

animationSpec the FiniteAnimationSpec for this animation, spring by default
initialAlpha the starting alpha of the enter transition, 0f by default

fadeOut

public fun fadeOut(
        animationSpec: FiniteAnimationSpec<Float> =
            SpatialTransitionDefaults.DefaultAlphaAnimationSpec,
        targetAlpha: Float = 0f,
    ): SpatialExitTransition

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

slideIn

public fun slideIn(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        initialOffset: Density.(fullSize: IntVolumeSize) -> IntVolumeOffset,
    ): SpatialEnterTransition

This slides in the content of the transition, from a starting offset defined in initialOffset to IntVolumeOffset(0, 0, 0). The direction of the slide can be controlled by configuring the initialOffset. A positive x value means sliding from right to left, whereas a negative x value will slide the content to the right. Similarly positive and negative y values correspond to sliding up and down, respectively, and positive and negative z values correspond to sliding closer and further, respectively.

If the sliding is only desired along one axis, consider using slideInHorizontally, slideInVertically, or slideInDepth.

initialOffset is a lambda that takes the full size of the content and returns an offset. This allows the offset to be defined proportional to the full size, or as an absolute value.

Parameters

animationSpec the animation used for the slide-in, spring by default.
initialOffset a lambda that takes the full size of the content and returns the initial offset for the slide-in

slideInHorizontally

public fun slideInHorizontally(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        initialOffsetX: Density.(fullWidth: Int) -> Int = { -it / 2 },
    ): SpatialEnterTransition

This slides in the content horizontally, from a starting offset defined in initialOffsetX to 0 pixels. The direction of the slide can be controlled by configuring the initialOffsetX. A positive value means sliding from right to left, whereas a negative value would slide the content from left to right.

initialOffsetX is a lambda that takes the full width of the content and returns an offset. This allows the starting offset to be defined proportional to the full size, or as an absolute value. It defaults to return half of negative width, which would offset the content to the left by half of its width, and slide towards the right.

Parameters

animationSpec the animation used for the slide-in, spring by default.
initialOffsetX a lambda that takes the full width of the content in pixels and returns the initial offset for the slide-in, by default it returns -fullWidth/2

slideInVertically

public fun slideInVertically(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        initialOffsetY: Density.(fullHeight: Int) -> Int = { -it / 2 },
    ): SpatialEnterTransition

This slides in the content vertically, from a starting offset defined in initialOffsetY to 0 pixels. The direction of the slide can be controlled by configuring the initialOffsetY. A positive value means sliding from top to bottom, whereas a negative value would slide the content from bottom to top.

initialOffsetY is a lambda that takes the full height of the content and returns an offset. This allows the starting offset to be defined proportional to the full size, or as an absolute value. It defaults to return half of negative height, which would offset the content down by half of its height, and slide upwards.

Parameters

animationSpec the animation used for the slide-in, spring by default.
initialOffsetY a lambda that takes the full height of the content in pixels and returns the initial offset for the slide-in, by default it returns -fullHeight/2

slideInDepth

public fun slideInDepth(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        initialOffsetZ: Density.(fullDepth: Int) -> Int = { -20.dp.roundToPx() },
    ): SpatialEnterTransition

This slides in the content depthwise, from a starting offset defined in initialOffsetZ to 0 pixels. The direction of the slide can be controlled by configuring the initialOffsetZ. A positive value means sliding from close to far, whereas a negative value would slide the content from far to close.

initialOffsetZ is a lambda that takes the full depth of the content and returns an offset. This allows the starting offset to be defined proportional to the full size, or as an absolute value.

Unlike slideInVertically and slideInHorizontally, this defaults to sliding in from 20dp away from the neutral depth point. This is because many commonly-animated Spatial elements, such as SpatialPanel, report a depth of 0.

Parameters

animationSpec the animation used for the slide-in, spring by default.
initialOffsetZ a lambda that takes the full height of the content in pixels and returns the initial offset for the slide-in, by default it returns -20.dp.toPx()

slideOut

public fun slideOut(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        targetOffset: Density.(fullSize: IntVolumeSize) -> IntVolumeOffset,
    ): SpatialExitTransition

This slides out the content of the transition, from an offset of IntVolumeOffset(0, 0, 0) to the target offset defined in targetOffset. The direction of the slide can be controlled by configuring the targetOffset. A positive x value means sliding from left to right, whereas a negative x value would slide the content from right to left. Similarly, positive and negative y values correspond to sliding down and up, respectively, and positive and negative z values correspond to sliding closer and further, respectively.

If the sliding is only desired along one axis, consider using slideOutHorizontally, slideOutVertically, or slideOutDepth.

targetOffset is a lambda that takes the full size of the content and returns an offset. This allows the offset to be defined proportional to the full size, or as an absolute value.

Parameters

animationSpec the animation used for the slide-out, spring by default.
targetOffset a lambda that takes the full size of the content and returns the target offset for the slide-out

slideOutHorizontally

public fun slideOutHorizontally(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        targetOffsetX: Density.(fullWidth: Int) -> Int = { -it / 2 },
    ): SpatialExitTransition

This slides out the content horizontally, from 0 to a target offset defined in targetOffsetX in pixels. The direction of the slide can be controlled by configuring the targetOffsetX. A positive value means sliding to the right, whereas a negative value would slide the content towards the left.

targetOffsetX is a lambda that takes the full width of the content and returns an offset. This allows the target offset to be defined proportional to the full size, or as an absolute value. It defaults to return half of negative width, which would slide the content to the left by half of its width.

Parameters

animationSpec the animation used for the slide-out, spring by default.
targetOffsetX a lambda that takes the full width of the content and returns the initial offset for the slide-in, by default it returns fullWidth/2

slideOutVertically

public fun slideOutVertically(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        targetOffsetY: Density.(fullHeight: Int) -> Int = { -it / 2 },
    ): SpatialExitTransition

This slides out the content vertically, from 0 to a target offset defined in targetOffsetY in pixels. The direction of the slide-out can be controlled by configuring the targetOffsetY. A positive target offset means sliding down, whereas a negative value would slide the content up.

targetOffsetY is a lambda that takes the full Height of the content and returns an offset. This allows the target offset to be defined proportional to the full height, or as an absolute value. It defaults to return half of the negative height, which would slide the content up by half of its Height.

Parameters

animationSpec the animation used for the slide-out, spring by default.
targetOffsetY a lambda that takes the full Height of the content and returns the target offset for the slide-out, by default it returns fullHeight/2

slideOutDepth

public fun slideOutDepth(
        animationSpec: FiniteAnimationSpec<IntVolumeOffset> =
            SpatialTransitionDefaults.DefaultSlideAnimationSpec,
        targetOffsetZ: Density.(fullDepth: Int) -> Int = { -20.dp.roundToPx() },
    ): SpatialExitTransition

This slides out the content depthwise, from 0 to a target offset defined in targetOffsetZ in pixels. The direction of the slide-out can be controlled by configuring the targetOffsetZ. A positive value means sliding from close to far, whereas a negative value would slide the content from far to close.

targetOffsetZ is a lambda that takes the full depth of the content and returns an offset. This allows the target offset to be defined proportional to the full depth, or as an absolute value.

Unlike slideInVertically and slideInHorizontally, this defaults to sliding in from 20dp away from the neutral depth point. This is because many commonly-animated Spatial elements, such as SpatialPanel, report a depth of 0.

Parameters

animationSpec the animation used for the slide-out, spring by default.
targetOffsetZ a lambda that takes the full depth of the content and returns the target offset for the slide-out, by default it returns -20.dp.toPx()