Last active
November 18, 2025 21:17
-
-
Save ryancfogarty/e551a326922b1868bc9d62e82da9e66f to your computer and use it in GitHub Desktop.
animated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | |
| ) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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