Skip to content

Commit

Permalink
[Compose] Ensure LottieClipSpec is always respected (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeal authored Jul 18, 2021
1 parent 194d96d commit 4373eba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4373eba

Please sign in to comment.