airbnb / lottie-ios

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

tvOS: the key values which set with `setValueProvider` disappearing while switching between `.automatic` and `.mainThread` #2163

Closed joohae-kim closed 1 year ago

joohae-kim commented 1 year ago

Which Version of Lottie are you using?

Lottie 4.2.0

Expected Behavior

The values set by setValueProvider are kept internally and transferred between Animation Layers

Actual Behavior

  1. The following code is not working on tvOS because Lottie created CoreAnimationLayer when assigning animation of the view
  2. In CoreAnimationLayer.display(), it fails to setupAnimation() due The Core Animation rendering engine doesn't currently support applying trims to filled shapes
  3. create MainThreadAnimationLayer for fallback handling
  4. the valueProviders are not transferred to the new animation layer
    let savingAnimationView = LottieAnimationView()
    savingAnimationView.animation = LottieAnimation.named("CloudUpdating")
    let colorProvider = ColorValueProvider(UIColor(verkada: .charcoal).lottieColorValue)
    let keyPath = AnimationKeypath(keypath: "**.Color")
    savingAnimationView.setValueProvider(colorProvider, keypath: keyPath)
    savingAnimationView.play()
    savingAnimationView.loopMode = .loop
    addArrangedSubview(savingAnimationView)
    savingAnimationView.size(CGSize(width: 40, height: 40))

I have added the code at the end of fileprivate func makeAnimationLayer(usingEngine renderingEngine: RenderingEngineOption) method of LottieAnimationView, but not sure it will not cause any issue

    valueProviders.forEach({ valueProvider in
      animationLayer.setValueProvider(valueProvider.value, keypath: valueProvider.key)
    })

Animation JSON

calda commented 1 year ago

Thanks for the report. Fixed in #2164.

joohae-kim commented 1 year ago

thank you it works on my code also