lottie-ios icon indicating copy to clipboard operation
lottie-ios copied to clipboard

Adds .lottie file load capability to LottieAnimation

Open eharrison opened this issue 3 years ago • 1 comments

Adds support to parse .lottie files the dotLottie format (dotlottie.io) is a zip file with animation.json bundled along with image resources, and manifest

Motivation:

  • Make .lottie file a new standard for lottie animations
  • The update is already supported in Android player (https://github.com/airbnb/lottie-android/pull/1660)

Changes

  • Added internal classes of ZIPFoundation (required to decompress the .lottie file)
  • Added .lottie file parsing as a fallback to loading json animation data
  • .lottie file also applies speed, loop mode and imageProviderSettings according to it's content

eharrison avatar Oct 19 '22 20:10 eharrison

Hello! Here's Evandro. Head of mobile @ LottieFiles. Sending this as an effort to make .lottie more accessible. Please let me know if you see any issues. Thank you! :)

eharrison avatar Oct 19 '22 20:10 eharrison

In noticed CI is failing when using Xcode 12, presumably because support SPM dependencies in Xcode projects wasn't added until Xcode 13.

In https://github.com/airbnb/lottie-ios/pull/1787 I bumped the minimum supported Xcode version to Xcode 13 (which bumps the minimum supported Swift version to 5.5). This should fix that CI failure, and will also let use use newer Swift features like async / await. (You'll need to rebase this PR after #1787 is merged)

calda avatar Oct 21 '22 15:10 calda

Amazing! Thank you for the comments! I'll check them out.
Also, I may need help with Carthage, haven't done this before and not sure how the dependency is added.

eharrison avatar Oct 21 '22 15:10 eharrison

Hah, I also don't know how to add a dependency to a Carthage library. I can help take a look. If we can't get it to work by default we may have to wrap the ZIPFoundation code in #canImport directives and require Carthage consumers to integrate ZIPFoundation manually.

calda avatar Oct 21 '22 15:10 calda

Can we explore ways to make this dependency opt-in since a lot of people won’t need it?

for example:

  • Make this another module
  • Expose a ZIPProvider protocol that consumers are expect to implement in their apps and inject in LottieConfiguration or something similar

Besides adding a dependency for people who might not need it, this could cause conflicts if another version of the dependency is already used by the app.

marcelofabri avatar Oct 21 '22 17:10 marcelofabri

That makes sense to me. We could put all of the .lottie-related functionality in a separate DotLottie module that includes the ZIPFoundation dependency and has to be imported separately.

This should also fix our Carthage build issue, since we could simply not make the new module available on Carthage.

Thoughts @eharrison?

calda avatar Oct 21 '22 17:10 calda

Yes, I agree that the dependency is not ideal. It can definitely cause problems for users that already use ZIPFoundation.

Although, it would be awesome to have dotLottie directly inside lottie-ios, making it easier to use.

Perhaps, let me spend some time trying not to need the dependency, as it's literally called in a single place to decompress the file. There might be a simpler solution for this. I'll research and experiment.

eharrison avatar Oct 21 '22 17:10 eharrison

Hey hey, so I have added the necessary Zip dependency inside the app, cleaning up everything we don't need to make it run in the supported platforms. Let me know if you find any issue.

eharrison avatar Oct 31 '22 12:10 eharrison

Currently there is issue when play() method getting called but animation is not loaded yet. Especially for local .lottie files,

// AnimationViewInitializers
DotLottieFile.named(name, bundle: bundle, dotLottieCache: dotLottieCache) { result in
      guard case Result.success(let lottie) = result else { return }
      self.loadAnimation(animationId, from: lottie)
    }

there is currently no way to know when it is ready to play or how to properly handle this. Most of my dotLottie files are not playing, just stuck in first frame because it returns in following block:

// LottieAnimationView
public func play(completion: LottieCompletionBlock? = nil) {
    guard let animation = animation else {
      return //here
    }
    ...
  }

I think it would be nice to have some ways to handle it

rasberik avatar Nov 10 '22 02:11 rasberik

@eharrison @calda

rasberik avatar Nov 10 '22 02:11 rasberik

@rasberik, could you file an issue and ideally also provide a sample project that reproduces the issue?

calda avatar Nov 10 '22 03:11 calda

@rasberik, could you file an issue and ideally also provide a sample project that reproduces the issue?

@calda

Thanks, I prepared a PR here: https://github.com/airbnb/lottie-ios/pull/1802 We can continue the discussion there if its ok?

Sample project creation might take me a while due to busy schedule, my apologies. Files Im using cant be shared unfortunately 🙏

I believe using .lottie file over 50-100kb will be more than enough to reproduce the issue:

let lottieAnimationView = LottieAnimationView(dotLottieName: resourceName, bundle: bundle)
... (layout) 
lottieAnimationView.play()

rasberik avatar Nov 10 '22 03:11 rasberik

@calda Will this be enough as reproduction evidence?

https://github.com/rasberik/lottie-ios/pull/1/files

rasberik avatar Nov 10 '22 03:11 rasberik

Helpful, thanks!

calda avatar Nov 10 '22 03:11 calda

@calda I separated tests and added to https://github.com/airbnb/lottie-ios/pull/1802

rasberik avatar Nov 10 '22 04:11 rasberik