This slides in the content horizontally, from a starting offset defined in [initialOffsetX] to 0 pixels.
SlideTransition
@Composable
fun SlideTransition() {
var visible by remember { mutableStateOf(true) }
AnimatedVisibility(
visible = visible,
enter =
slideInHorizontally(animationSpec = tween(durationMillis = 200)) { fullWidth ->
// Offsets the content by 1/3 of its width to the left, and slide towards right
// Overwrites the default animation with tween for this slide animation.
-fullWidth / 3
} +
fadeIn(
// Overwrites the default animation with tween
animationSpec = tween(durationMillis = 200)
),
exit =
slideOutHorizontally(animationSpec = spring(stiffness = Spring.StiffnessHigh)) {
// Overwrites the ending position of the slide-out to 200 (pixels) to the right
200
} + fadeOut(),
) {
// Content that needs to appear/disappear goes here:
Box(Modifier.fillMaxWidth().requiredHeight(200.dp)) {}
}
}