Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use LottieAnimation in Jetpack Compose for Icon

Is there any way to use a JSON animation file using LottieAnimation in Jetpack Compose for an interactive element such as a to-do list's checkmark so that it animates when clicked?

I currently have a Row with Icon and a Column that further contains title and subtitle. I want this Icon to have a Lottie Animation.

like image 761
Caped Crusader Avatar asked Oct 21 '25 13:10

Caped Crusader


1 Answers

You can use the LottieAnimation composable.

Something like:

var isPlaying by remember { mutableStateOf(false) }

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.heart))
val progress by animateLottieCompositionAsState(
    composition,
    isPlaying = isPlaying,
)

Row(verticalAlignment = Alignment.CenterVertically) {
    LottieAnimation(
        composition = composition,
        progress = { progress },
        modifier = Modifier.clickable{ isPlaying = !isPlaying }
    )

    Text("Title", )
}

enter image description here

like image 199
Gabriele Mariotti Avatar answered Oct 24 '25 02:10

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!