I am trying to get what works in LottieAnimationView, playing compositions sequentially. After trying this code I am observing a bug where the last frame of the last played sequence doesn't disappear and animations leave a trail of frames from sequences that stopped playing. Is it a problem in my code or Lottie Compose doesn't support this yet? I was hoping to update "composition" as a mutable property but to no avail.
@Composablefun Play(file: Int) { val composition by rememberLottieComposition( LottieCompositionSpec.RawRes(file) ) val progress by animateLottieCompositionAsState(composition) LottieAnimation( composition = composition, progress = { progress } ) if (progress == 1f) { // compute UI-blocking functions Play(nextFile) }}
Edit:
With this code, there is no trailing but animations flicker upon starting the next sequence. In XML it works flawlessly.
@Composablefun Play() { @Composable fun c1(): Pair<LottieComposition?, Float> { val composition by rememberLottieComposition( LottieCompositionSpec.RawRes(R.raw.anim1) ) val p by animateLottieCompositionAsState(composition) return composition to p } @Composable fun c2(): Pair<LottieComposition?, Float> { val composition by rememberLottieComposition( LottieCompositionSpec.RawRes(R.raw.anim2) ) val p by animateLottieCompositionAsState(composition) return composition to p } val dir = remember { mutableStateOf(false) } val p = if (dir.value) c1() else c2() LottieAnimation( composition = p.first, progress = { p.second } ) if (p.second == 1f) { // ui-blocking dir.value = !dir.value }}