Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compose] Ensure LottieClipSpec is always respected #1848

Merged
merged 1 commit into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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