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

LottieAnimationView layout stuck in infinite loop #2310

Closed
via-guy opened this issue Feb 6, 2024 · 5 comments · Fixed by #2316
Closed

LottieAnimationView layout stuck in infinite loop #2310

via-guy opened this issue Feb 6, 2024 · 5 comments · Fixed by #2316

Comments

@via-guy
Copy link

via-guy commented Feb 6, 2024

Which Version of Lottie are you using?

Lottie 4.3.0

Expected Behavior

App does not get stuck

Actual Behavior

App is stuck in an infinite loop.
There was a bug introduced in commit ecdadec where the function layoutAnimation in Sources/Public/Animation/LottieAnimationView.swift calls setNeedsLayout from within a layout function. This causes the layout function to be called again on the next runloop, and again and again repeatedly, causing the UI thread to freeze. I believe removing this line will fix the issue.

@calda
Copy link
Member

calda commented Feb 6, 2024

Can you share a sample project that demonstrates this issue?

@via-guy
Copy link
Author

via-guy commented Feb 7, 2024

@via-guy
Copy link
Author

via-guy commented Feb 7, 2024

There seems to be an issue when you have a container view for it.

let animationView = LottieAnimationView(name: "loader")
containerView.addSubview(animationView)
animationView.translatesAutoresizingMaskIntoConstraints = false
containerView.addConstraints(NSLayoutConstraint.constraints(
    withVisualFormat: "V:|-(0)-[contentView]-(0)-|",
    options: NSLayoutConstraint.FormatOptions.alignAllLastBaseline,
    metrics: nil,
    views: ["contentView": animationView]
))
containerView.addConstraints(NSLayoutConstraint.constraints(
    withVisualFormat: "H:|-(0)-[contentView]-(0)-|",
    options: NSLayoutConstraint.FormatOptions.alignAllLastBaseline,
    metrics: nil,
    views: ["contentView": animationView]
))
animationView.backgroundBehavior = .pauseAndRestore
animationView.viewportFrame = animationView.bounds
animationView.loopMode = .loop
animationView.play()

@calda
Copy link
Member

calda commented Feb 13, 2024

This appears to be because you're setting animationView.viewportFrame = animationView.bounds.

I don't think that line is necessary -- if I remove it, your demo runs correctly.

However, this infinite loop happens any time viewportFrame is non-nil, so is definitely a regression we should fix.

@calda
Copy link
Member

calda commented Feb 13, 2024

Here's a fix: #2316

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

Successfully merging a pull request may close this issue.

2 participants