Adds .lottie file load capability to LottieAnimation
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
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! :)
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)
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.
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.
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.
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?
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.
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.
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
@eharrison @calda
@rasberik, could you file an issue and ideally also provide a sample project that reproduces the issue?
@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()
@calda Will this be enough as reproduction evidence?
https://github.com/rasberik/lottie-ios/pull/1/files
Helpful, thanks!
@calda I separated tests and added to https://github.com/airbnb/lottie-ios/pull/1802