slideInVertically
Function
Common
public fun slideInVertically(
animationSpec: FiniteAnimationSpec<IntOffset> =
spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset.VisibilityThreshold,
),
initialOffsetY: (fullHeight: Int) -> Int = { -it / 2 },
): EnterTransition
This slides in the content vertically, from a starting offset defined in initialOffsetY
to 0
in pixels. The direction of the slide can be controlled by configuring the initialOffsetY
.
A positive initial offset means sliding up, whereas a negative value would slide the content
down.
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 height, or as an absolute
value. It defaults to return half of negative height, which would offset the content up by half
of its Height, and slide down.
Parameters
animationSpec | the animation used for the slide-in, spring by default. |
initialOffsetY | a lambda that takes the full Height of the content and returns the initial offset for the slide-in, by default it returns -fullHeight/2 |
Code Examples
FullyLoadedTransition
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun FullyLoadedTransition() {
var visible by remember { mutableStateOf(true) }
AnimatedVisibility(
visible = visible,
enter =
slideInVertically(
// Start the slide from 40 (pixels) above where the content is supposed to go, to
// produce a parallax effect
initialOffsetY = { -40 }
) +
expandVertically(expandFrom = Alignment.Top) +
scaleIn(
// Animate scale from 0f to 1f using the top center as the pivot point.
transformOrigin = TransformOrigin(0.5f, 0f)
) +
fadeIn(initialAlpha = 0.3f),
exit = slideOutVertically() + shrinkVertically() + fadeOut() + scaleOut(targetScale = 1.2f),
) {
// Content that needs to appear/disappear goes here:
Text("Content to appear/disappear", Modifier.fillMaxWidth().requiredHeight(200.dp))
}
}