Composable Function

animateValue

Creates an animation of type T that runs infinitely as a part of the given InfiniteTransition.

InfiniteTransitionAnimateValueSample

@Sampled
@Composable
fun InfiniteTransitionAnimateValueSample() {
    // Creates an [InfiniteTransition] instance to run child animations.
    val infiniteTransition = rememberInfiniteTransition()
    // Infinitely animate a Dp offset from 0.dp to 100.dp
    val offsetX by
        infiniteTransition.animateValue(
            initialValue = 0.dp,
            targetValue = 100.dp,
            typeConverter = Dp.VectorConverter,
            animationSpec =
                infiniteRepeatable(
                    animation =
                        keyframes {
                            durationMillis = 500
                            0.dp at 200 // ms
                            80.dp at 300 using FastOutLinearInEasing
                        }
                    // Use the default RepeatMode.Restart to start from 0.dp after each iteration
                ),
        )

    Box(Modifier.offset(x = offsetX)) {
        // Content goes here
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: