rememberLottieAnimatable を使います。
- @Preview
- @Composable
- fun LottieAnimationSample() {
- val composition by rememberLottieComposition(
- LottieCompositionSpec.RawRes(R.raw.lottie_animation)
- )
- val lottieAnimatable = rememberLottieAnimatable()
- val coroutineScope = rememberCoroutineScope()
-
- Box(
- contentAlignment = Alignment.Center,
- modifier = Modifier
- .fillMaxSize()
- .pointerInput(Unit) {
- detectTapGestures(
- onTap = {
- coroutineScope.launch {
- lottieAnimatable.animate(composition)
- }
- },
- )
- }
- ) {
- LottieAnimation(
- composition = composition,
- progress = { lottieAnimatable.value },
- modifier = Modifier.size(72.dp),
- )
- }
- }
@Preview
@Composable
fun LottieAnimationSample() {
val composition by rememberLottieComposition(
LottieCompositionSpec.RawRes(R.raw.lottie_animation)
)
val lottieAnimatable = rememberLottieAnimatable()
val coroutineScope = rememberCoroutineScope()
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures(
onTap = {
coroutineScope.launch {
lottieAnimatable.animate(composition)
}
},
)
}
) {
LottieAnimation(
composition = composition,
progress = { lottieAnimatable.value },
modifier = Modifier.size(72.dp),
)
}
}
0 件のコメント:
コメントを投稿