Skip to content

Instantly share code, notes, and snippets.

@ryancfogarty
Last active November 18, 2025 21:17
Show Gist options
  • Select an option

  • Save ryancfogarty/e551a326922b1868bc9d62e82da9e66f to your computer and use it in GitHub Desktop.

Select an option

Save ryancfogarty/e551a326922b1868bc9d62e82da9e66f to your computer and use it in GitHub Desktop.
animated
private suspend fun LottieAnimatable.animatedSnapTo(
composition: LottieComposition?,
targetProgress: Float,
velocity: Float = ANIMATED_SNAP_VELOCITY,
) {
val currentProgress = this.progress
if (currentProgress == targetProgress) return
coroutineScope {
val direction = (targetProgress - currentProgress).unitVector()
val speed = velocity * direction
val clipSpec = if (direction > 0) {
LottieClipSpec.Progress(currentProgress, targetProgress)
} else {
LottieClipSpec.Progress(targetProgress, currentProgress)
}
animate(
composition = composition,
speed = speed,
clipSpec = clipSpec,
iteration = 1,
iterations = 1,
initialProgress = currentProgress,
)
}
}
LaunchedEffect(page) {
animatable.animatedSnapTo(composition, page.startProgress, 5f)
val pageClipSpec = LottieClipSpec.Progress(page.startProgress, nextPage.endProgress)
animatable.animate(composition, clipSpec = pageClipSpec, speed = 1f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment