Search code examples
android-jetpack-composelottie

Lottie Compose: how to loop the animation indefinitely


I have the following Lottie animation that plays only once, how can I make it play indefinitely?

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.search_animation))
LottieAnimation(composition = composition)

Solution

  • Update 2023-09-05
    There is an overloaded version of the LottieAnimation composable that merges the LottieAnimation and animateLottieCompositionAsState parameters.

    LottieAnimation(
        composition,
        iterations = LottieConstants.IterateForever,
    )
    

    Source: https://airbnb.io/lottie/#/android-compose?id=lottieanimation-overload

    Old answer
    You can tell Lottie to iterate an animation forever via the progress parameter:

    val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.search_animation))
    val progress by animateLottieCompositionAsState(composition = composition, iterations = LottieConstants.IterateForever)
    LottieAnimation(
        composition = composition,
        progress = { progress },
    )
    

    Source: https://airbnb.io/lottie/#/android-compose?id=animatelottiecompositionasstate