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)
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)
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
just to aid those future wanderers that stumble upon this... These days it's changed to something more like this:
LottieAnimation(
composition = composition,
iterations = LottieConstants.IterateForever,
...
```
you can just simply add app:lottie_loop="true"
at your xml for your LottieAnimationView.
© 2022 - 2024 — McMap. All rights reserved.