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

guard self.window != nil prevents layer animation from playing #999

Closed
jeffepic opened this issue Jul 31, 2019 · 5 comments
Closed

guard self.window != nil prevents layer animation from playing #999

jeffepic opened this issue Jul 31, 2019 · 5 comments
Labels

Comments

@jeffepic
Copy link

This issue is a:

  • [] Non-Crashing Bug (Visual or otherwise)

Which Version of Lottie are you using?

Lottie 3.1.2

What Platform are you on?

  • iOS

What Language are you in?

  • Swift

Expected Behavior

Actual Behavior

Code Example

Adding an AnimationView's layer to another CALayer, the animation will never play because of this line in AnimationView.swift:
guard self.window != nil else { waitingToPlayAimation = true; return }

If I comment that out, it works as expected. The reason is that I am not adding the AnimationView to the view hierarchy, and therefore its window is nil. Layer does not have a window property.

works:
view.addSubview(lottieView)

does not work:
customLayer.addSublayer(lottieView.layer)

I think I understand the purpose of that line, you don't want it playing if it isn't on the screen, but maybe an option could be added for layer animations to bypass that?

@jeffepic jeffepic changed the title guard self.window != nil prevents layer animation from working guard self.window != nil prevents layer animation from playing Jul 31, 2019
@damikdk
Copy link

damikdk commented Aug 6, 2019

I spent days trying to export CALayer without real UIView rendered on the screen (through AVMutableVideoComposition and AVAssetExportSession) and I got the same results. This line really ruin the coolest way to export animations.

@croossin
Copy link

croossin commented Aug 6, 2019

I am also seeing this issue... even when adding an AnimationView directly to the .xib...

@ole-kr-stumpf
Copy link

I had this issue, and I resolved it by moving the initialisation of AnimationView, i.e. let animationView = AnimationView() to inside of makeUIView.
Also, this was an issue only on iOS v. 14.1, but not on 14.2

@devmea
Copy link

devmea commented Mar 25, 2022

Using version 3.1.5 and came across this issue.
I have a collectionView with several AnimationViews, and it works the first time I scroll down. When I scroll back up, and I instantiate a new AnimationView, its window is returning nil.

Edit: updated to 3.3.0 and issue persists.

@calda
Copy link
Member

calda commented Jul 13, 2022

Adding an AnimationView's layer to another CALayer

Closing since I don't think this is a supported way to use a UIView subclass

@calda calda closed this as completed Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants