Skip to content

Instantly share code, notes, and snippets.

@remziakgoz
Created June 20, 2025 10:24
Show Gist options
  • Save remziakgoz/28d2379d3934b5e9cc6779d27d25eb0f to your computer and use it in GitHub Desktop.
Save remziakgoz/28d2379d3934b5e9cc6779d27d25eb0f to your computer and use it in GitHub Desktop.
Jetpack Compose: Control Lottie Animations with Animatable
// StartButton.kt
package com.remziakgoz.coffeepomodoro.presentation.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.*
@Composable
fun StartButton(
modifier: Modifier = Modifier,
shouldStart: Boolean,
onClick: () -> Unit
) {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("coffeeButton.json"))
var isAnimating by remember { mutableStateOf(false) }
val animatable = rememberLottieAnimatable()
LaunchedEffect(isAnimating) {
composition?.let {
animatable.animate(
composition = it,
clipSpec = if (isAnimating)
LottieClipSpec.Progress(0f, 0.5f)
else
LottieClipSpec.Progress(0.5f, 1f)
)
}
}
LottieAnimation(
composition = composition,
progress = { animatable.progress },
modifier = modifier
.size(300.dp)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
isAnimating = !isAnimating
onClick()
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment