Lottie-ios: After upgrading Lottie to v. 3.x animations no longer play

Created on 21 Mar 2019  Â·  11Comments  Â·  Source: airbnb/lottie-ios

This issue is a:

Crashing Bug (visually)

Which Version of Lottie are you using?

Lottie 3.0

What Platform are you on?

iOS

What Language are you in?

Swift

Expected Behavior

After upgrading from 2.x to 3.0 animations no longer play.

Actual Behavior

I expected the animations would play like in pre 3.x versions

Code Example

I have a property like this:

 var backgroundAnimation: AnimationView = {
        let animationView = AnimationView(name: "bkgd_blue")
        animationView.loopMode = .loop
        animationView.contentMode = .scaleAspectFill
        return animationView
    }()

Then later I have this:

backgroundAnimation.frame = view.frame
        view.addSubview(backgroundAnimation)
        view.sendSubviewToBack(backgroundAnimation)
        backgroundAnimation.play()

When I "po" the backgroundAnimation I get this:
<Lottie.AnimationView: 0x14fd243e0; frame = (0 0; 375 667); clipsToBounds = YES; layer = <CALayer: 0x1c022fea0>>
If I "po" backgroundAnimation.animation I get nil. I perhaps expected an animation, but since I loaded the animation via the AnimationView's initializer I guess something is going on in the background.

Most helpful comment

I resolved this issue by removing the .json in the animation name parameter and removing the animation from the asset catalogue.

Previous :

// Doesn't work since Lottie 3.x
let animationView = AnimationView(name: "my_animation.json")

Updated :

// Work with Lottie 3.x
let animationView = AnimationView(name: "my_animation")

All 11 comments

Hmm seems like the animation isnt loading properly. Can you tell me more about your setup so I can debug? Is the animation in the main bundle? Does it have a json extentsion?
If you do
let url = Bundle.main.url(forResource: "bkgd_blue", withExtension: "json", subdirectory: nil)
what do you get?

Same issue here, the majority of our animations don't play anymore but are well loaded from the bundle. For some animations, there are playing correctly, or some layers are displayed.
It's like the layer interpretation doesn't work as the previous Objective-C version.

@bill350 If you can give me some more context id love to help you fix the issue. Are you having the same issue that where .animation is nil after loading up the animation? Are you loading from the main bundle or another bundle? Have you tried the one liner above and what does it return?

If the animation is loading (meaning that .animation is not nil) then you are having a separate issue than the one in this thread. Please file a new issue so we can track it separately.

Got a fix here: https://github.com/airbnb/lottie-ios/pull/815 please pull and verify.

Just a minor comment. I did not try the fix by @buba447 yet.
But I discovered this:
If I moved the animation JSON files form the assets catalog, and just had them as plain JSON files in Xcode the animations played again. So it seems the new version doesn't support the assets catalogue?

But unfortunately that was only the tip of the iceberg for me with regards to the new Swift version of Lottie. I had to go back to the 2.5.x version to get it working again. My problem is that all of our animations are placed in the parent view differently than before. Location and size are all different. I tried going through all of them but I was spending a lot of time while not really understanding why the animations was in the wrong place suddenly.

It seems the 3.x version works much differently than 2.x.

There was a bug with scaleAspectFill in 3.0 that has been resolved with 3.0.3. This should fix your scale and sizing issues.
Please let me know if you continue to have issues so that they can be fixed! Thanks!

On Mar 25, 2019, at 09:36, Jacob Rohde notifications@github.com wrote:

Just a minor comment. I did not try the fix by @buba447 yet.
But I discovered this:
If I moved the animation JSON files form the assets catalog, and just had them as plain JSON files in Xcode the animations played again. So it seems the new version doesn't support the assets catalogue?

But unfortunately that was only the tip of the iceberg for me with regards to the new Swift version of Lottie. I had to go back to the 2.5.x version to get it working again. My problem is that all of our animations are placed in the parent view differently than before. Location and size are all different. I tried going through all of them but I was spending a lot of time while not really understanding why the animations was in the wrong place suddenly.

It seems the 3.x version works much differently than 2.x.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@buba447
That is great to hear. I would much prefer to upgrade, I will try again soon.
Do you support to have the JSON files in the assets catalogue?
Also, thx for the awesome work on Lottie! It is an amazing lib.

Support for json in the asset catalogue isn't directly supported but should
be easy enough to add. Ill put it on my list.

On Mon, Mar 25, 2019 at 9:54 AM Jacob Rohde notifications@github.com
wrote:

@buba447 https://github.com/buba447
That is great to hear. I would much prefer to upgrade, I will try again
soon.
Do you support to have the JSON files in the assets catalogue?
Also, thx for the awesome work on Lottie! It is an amazing lib.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/airbnb/lottie-ios/issues/807#issuecomment-476207233,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABHCzOsLa-wpYkH65jLb9ET1L_ZsNz8mks5vaNUXgaJpZM4cA8lO
.

I resolved this issue by removing the .json in the animation name parameter and removing the animation from the asset catalogue.

Previous :

// Doesn't work since Lottie 3.x
let animationView = AnimationView(name: "my_animation.json")

Updated :

// Work with Lottie 3.x
let animationView = AnimationView(name: "my_animation")

I'm seeing this issue in 3.1.0 downgraded back to 3.0.3 and everything is okay

var backgroundAnimation: LOTAnimationView = {
let animationView = LOTAnimationView(name: "10173-success-lumina")
animationView.loopAnimation = true
animationView.contentMode = .scaleAspectFill
return animationView
}()

    backgroundAnimation.frame = view.frame
    view.addSubview(backgroundAnimation)
    view.sendSubviewToBack(backgroundAnimation)
    backgroundAnimation.play()
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rdd7 picture rdd7  Â·  4Comments

zhangjunmax picture zhangjunmax  Â·  3Comments

muraterd picture muraterd  Â·  5Comments

RamblinWreck77 picture RamblinWreck77  Â·  3Comments

JALsnipe picture JALsnipe  Â·  4Comments