In Android View System, We can use animation listener like below to get lottie animation callbacks.
playView = LottieAnimationView(this)
playView.addAnimatorListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
}
override fun onAnimationCancel(animation: Animator?) {
}
override fun onAnimationRepeat(animation: Animator?) {
}
})
How we can add listener using Jetpack Compose? i added below code currently to play the lottie animation. I want to receive the callback after animation play completed.
@Composable
fun PlayView() {
val animationSpec = remember { LottieAnimationSpec.RawRes(R.raw.play_anim) }
val result: LottieCompositionResult by remember { mutableStateOf(LottieCompositionResult.Loading) }
val context = LocalContext.current
LottieAnimation(
animationSpec,
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth()
)
if (result is LottieCompositionResult.Success) {
//start the next flow
}
}