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

animateLottieCompositionAsState doesn't respect min progress #1845

Closed
headsvk opened this issue Jul 15, 2021 · 1 comment · Fixed by #1848
Closed

animateLottieCompositionAsState doesn't respect min progress #1845

headsvk opened this issue Jul 15, 2021 · 1 comment · Fixed by #1848

Comments

@headsvk
Copy link
Contributor

headsvk commented Jul 15, 2021

Link to fork with a repro in the issue-repro module
https://github.com/headsvk/lottie-android/tree/bug/min-progress

Describe the bug
When animateLottieCompositionAsState is used with a clipSpec that has min progress greater than 0, the animation is played from beginning anyway. For example:

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.heart))
val state = animateLottieCompositionAsState(
    composition = composition,
    iterations = 1,
    clipSpec = LottieClipSpec.Frame(min = 33, max = 42),
)

Log.w("LOTTIE", "progress = ${state.progress}, isAtEnd = ${state.isAtEnd}")

LottieAnimation(
    composition = composition,
    progress = state.progress,
)

Steps To Reproduce
Steps to reproduce the behavior:

  1. Run issue-repro-compose
  2. Observe animation and logs

Expected:
Animation skips the first part with a grey heart, log shows:

W/LOTTIE: progress = 0.0, isAtEnd = true
W/LOTTIE: progress = 0.2845073, isAtEnd = false
W/LOTTIE: progress = 0.30209655, isAtEnd = false
W/LOTTIE: progress = 0.31037384, isAtEnd = false
W/LOTTIE: progress = 0.31916845, isAtEnd = false

Actual:
Animation plays from the beginning, log shows:

W/LOTTIE: progress = 0.0, isAtEnd = true
W/LOTTIE: progress = 0.0, isAtEnd = false
W/LOTTIE: progress = 0.009311951, isAtEnd = false
W/LOTTIE: progress = 0.01810657, isAtEnd = false
W/LOTTIE: progress = 0.02690119, isAtEnd = false
@headsvk
Copy link
Contributor Author

headsvk commented Jul 16, 2021

I debugged animateLottieCompositionAsState and the logic to reset to beginning is not triggered on first launch. That is probably correct.

        if (isPlaying && !wasPlaying && restartOnPlay) {
            animatable.resetToBeginning()
        }

But then initialProgress = animatable.progress is simply 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant