Lottie-ios: Play completion closure not called in Swift

Created on 23 Feb 2017  路  19Comments  路  Source: airbnb/lottie-ios

private func playAnimation() {
        self.animationView?.play(completion: { (completed) in 
        ...
        })
    }

With the last version (1.0.4) the animation is performed correctly, but the completion block is never called.

animationView is a retained variable (Swift)

fileprivate var animationView: LOTAnimationView?

and the entire view controller is (Obj-c)

@property (nonatomic, strong) SplashScreenViewController *splashScreenViewController;

Note: the bug seems incredibly intermittent O_o once every 5-6 run the closure is called.

Most helpful comment

Hey everyone! We are releasing an update that fixes this very soon!

All 19 comments

Which completion isn't being called? The LOT one or the UIView Animation one?
Is this on OS X or on iOS?
Im not seeing it on my end so I need a bit more context to fix :)

Ups, sorry, the 'self.animationView?.play' completion isn't called, the animation is there only for example.
Environment: iOS 10.2, simulator and iphone 7.

Some additional information:

The animation is initialized and started inside a View controller, and the VC is presented:

self.splashVC = SplashScreenViewController()
self.splashVC?.delegate = self
//self.present(self.splashVC!, animated: false, completion: nil) <---- doesn't work (completion block never called)
//self.showDetailViewController(self.splashVC!, sender: self) <---- work! (completion block called)
//self.show(self.splashVC!, sender: self) <---- doesn't work (completion block never called)

The VC is correctly persisted in memory.

Debugging the Lottie code i've noticed that the "play" method is called twice, the first time from my code and the second time:

screen shot 2017-02-28 at 10 38 40

update:

Presenting the view controller containing the LOTAnimationView modally with:
self.present(self.splashVC!, animated: true, completion: nil)
the completion block is called.

Instead, setting animated to false:
self.present(self.splashVC!, animated: false, completion: nil)
the completion block isn't called.

Is definitely some sort of race condition, if I set breakpoints in the LOTAnimationView in the various callers of _callCompletionIfNecesarry the majority of the times the completion block is called.

I'm continuing my attempts to use lottie, still hoping for help.
Now i've created a UIView named A with inside the LOTAnimationView named B configured at INIT time. Every method is called on main thread, included .play(completion: but the completion block is never called.

Should I provide example code?

here we go: not working Swift example: LINK

The SplashScreenView is almost identical to the one used in my app, only adapted.

+1 here

Have you guys solved this issue? I have the same issue now

@dandongyan nope, the lib is still broken, we solved it with a dirty workaround setting our own timer.
Let's hope for a fix in version 2.0

@federicocappelli all right, thank you, maybe i should also user timer

@federicocappelli Mind posting an example of your workaround?

We're running into this issue where Lottie doesn't call completion blocks if the animations happen when the app is in an inactive or backgrounded state (e.g. w/ wifi control panel showing / hiding)

@rob-keepsafe have fun:

public func playAnimation() {
        DispatchQueue.main.async {
            self.animationView?.play()
            //            self.animationView?.play(completion: { (finished) in //DO NOT WORK
            //                self.dismissAnimation()
            //            })
            //Note: set a timer is really bad, but lottie has a bug and the completion block isn't called, additionally the self.animationView.animationDuration is wrong. Bug reported in https://github.com/airbnb/lottie-ios/issues/118
            _ = Timer.scheduledTimer(timeInterval: TimeInterval(2.0),
                                     target: self,
                                     selector: #selector(self.dismissAnimation),
                                     userInfo: nil,
                                     repeats: false)
        }
    }

Ah, I see. Thanks! Unfortunately mine is an indefinitely timed spinner so I'll have to look for other ways

Hey everyone! We are releasing an update that fixes this very soon!

great news @buba447 thanks!

@buba447 First off, thank you! Any chance you could point me to the fix so I can patch locally for now? We're trying to release but hitting this when users show/hide the wifi control panel

As a workaround for the inactive/backgrounded app scenario, here's what we're doing for now:

  • When the app resigns active, we set a shouldAnimateWithLottie flag to false, reset all Lottie animations (e.g. pause them, set animation progress to 0, and hide them) and only use UIView based animations from that point forward
  • As soon as the person presses a button again (meaning the app is active / foregrounded again and we have a known state), we reset that flag and allow Lottie to do its thing

Should be fixed in Lottie 2.0! If you still have a problem please create a new issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

awschuerholz picture awschuerholz  路  3Comments

JALsnipe picture JALsnipe  路  4Comments

albertoNovo picture albertoNovo  路  3Comments

webdale picture webdale  路  5Comments

WZBbiao picture WZBbiao  路  5Comments