airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.78k stars 3.75k forks source link

Unable to reach the end of the animation when setting `.currentProgress` with `.coreAnimation` engine #2209

Closed m-yeroshenko closed 11 months ago

m-yeroshenko commented 1 year ago

Hi everyone!

First of all, thanks for such a great library for dealing with animations. I am sorry to say that I'm having an issue when using the latest version 4.3.3 (actually, it is also present on 4.3.0).

So, I have a few animation JSONs and have to control their progress with the SwiftUI.Slider view. When using the .mainThread rendering engine everything is fine, but once I switch to the .coreAnimation I cannot reach the animation's latest "frame".

I would appreciate any help with this.

Which Version of Lottie are you using?

Lottie 4.3.3

.mainThread behavior

https://github.com/airbnb/lottie-ios/assets/140485731/cd1dcb73-a5bf-49ee-8c88-bfa0c407c47f

.coreAnimation behavior

https://github.com/airbnb/lottie-ios/assets/140485731/f12ceaf1-f7ad-4260-8488-99d150496abf

Animation JSON

animation.json

Code to reproduce the behavior

import Lottie
import SwiftUI

struct SwiftUIView: View {
  @State
  private var currentProgress: Double = .zero

  let jsonURL = Bundle.main.url(
    forResource: "animation",
    withExtension: "json"
  )

  var body: some View {
    if let jsonURL {
      VStack {
        LottieView {
          await LottieAnimation.loadedFrom(url: jsonURL)
        }
        .configuration(.init(renderingEngine: .mainThread))
        // .configuration(.init(renderingEngine: .coreAnimation))
        .resizable()
        .currentProgress(currentProgress)
        Slider(value: $currentProgress, in: 0 ... 1.01)
      }
    }
  }
}

#Preview {
  SwiftUIView()
}
polurezov8 commented 1 year ago

Hello everyone!

I'm highlighting this critical issue with the .coreAnimation rendering engine. It's affecting our use of the Lottie library significantly, especially since we cannot access the animation's last frame.

If there's any known workaround or if the team is aware of this, it would be great to hear back. This issue is impacting our application's performance.

Thanks in advance for looking into it!

calda commented 11 months ago

Thanks for the report! This one was pretty interesting: https://github.com/airbnb/lottie-ios/pull/2254