Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 977
Roberto Leinardi Avatar asked Dec 05 '25 17:12

Roberto Leinardi


1 Answers

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

like image 80
Roberto Leinardi Avatar answered Dec 08 '25 22:12

Roberto Leinardi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!