我尝试在每次amount
变量的值发生变化时重新启动Lottie动画。
第一次更改值是成功的,但对该值的后续更改不会触发动画。
@Composable
private fun Lottie(
amount: Long
) {
var oldAmount by remember { mutableStateOf(0L) }
val currentAmount by remember { mutableStateOf(amount) }
val playAnimation = currentAmount != amount && oldAmount != 0L
oldAmount = currentAmount
val composition by rememberLottieComposition(
LottieCompositionSpec.RawRes(R.raw.my_animation)
)
val progress by animateLottieCompositionAsState(
composition,
isPlaying = playAnimation,
speed = 1f,
restartOnPlay = false,
cancellationBehavior = LottieCancellationBehavior.OnIterationFinish
)
LottieAnimation(composition = composition, progress = progress)
}
1条答案
按热度按时间xwbd5t1u1#
找到解决方案
用关键元素 Package 可组合件就成功了