Skip to content

InfiniteTransition

Create infinite animations that run continuously.

val infiniteTransition = rememberInfiniteTransition(label = "infinite")
// Pulsing animation
val scale by infiniteTransition.animateFloat(
initialValue = 1f,
targetValue = 1.2f,
animationSpec = infiniteRepeatable(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
),
label = "scale"
)
// Rotating animation
val rotation by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(2000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
),
label = "rotation"
)
// Color animation
val color by infiniteTransition.animateColor(
initialValue = Color.Red,
targetValue = Color.Blue,
animationSpec = infiniteRepeatable(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
),
label = "color"
)
Box(
Modifier
.scale(scale)
.rotate(rotation)
.background(color)
.size(100.dp)
)
ModeDescription
RepeatMode.RestartJump back to initial value
RepeatMode.ReverseAnimate back to initial value