diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimatable.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimatable.kt index db1a8bcfd4..051aa2165c 100644 --- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimatable.kt +++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimatable.kt @@ -261,7 +261,7 @@ private class LottieAnimatableImpl : LottieAnimatable { else -> progress + dProgress - maxProgress } if (progressPastEndOfIteration < 0f) { - progress += dProgress + progress = progress.coerceIn(minProgress, maxProgress) + dProgress } else { val durationProgress = maxProgress - minProgress val dIterations = (progressPastEndOfIteration / durationProgress).toInt() + 1 diff --git a/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieAnimatableImplTest.kt b/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieAnimatableImplTest.kt index e207733a31..7ef172e4fa 100644 --- a/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieAnimatableImplTest.kt +++ b/lottie-compose/src/test/java/com/airbnb/lottie/compose/LottieAnimatableImplTest.kt @@ -1,8 +1,10 @@ package com.airbnb.lottie.compose +import androidx.compose.animation.core.AnimationConstants import com.airbnb.lottie.LottieComposition import com.airbnb.lottie.LottieCompositionFactory import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.launch import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.withContext @@ -298,6 +300,23 @@ class LottieAnimatableImplTest { assertFrame(599, progress = 1f, isAtEnd = false, isPlaying = false, iterations = 3) } + @Test + fun testCompositionCreated() = runTest { + val clipSpec = LottieClipSpec.Frame(20, 25) + val job1 = launch { + anim.animate(null, clipSpec = clipSpec) + } + assertFrame(0, progress = 0f, clipSpec = clipSpec, isAtEnd = true, isPlaying = false, lastFrameNanos = AnimationConstants.UnspecifiedTime) + + job1.cancelAndJoin() + val job2 = launch { + anim.animate(composition, clipSpec = clipSpec, initialProgress = anim.progress) + } + + assertFrame(0, progress = 0.556f, clipSpec = clipSpec) + job2.cancelAndJoin() + } + private suspend fun assertFrame( frameTimeMs: Long, progress: Float,