-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Adds .lottie file load capability to LottieAnimation #1785
Conversation
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! :) |
Sources/Public/Animation/DotLottie/ZIPFoundation/Archive+BackingConfiguration.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. At a high level there are a few things we need to figure out:
- Can we incorporate ZIPFoundation using a package manager, instead of simply pasting its source into our repo?
- Can we load the
.lottie
file contents into memory and then delete the temporary directory we created when uncompressing it? - Instead of modifying the existing methods that create
LottieAnimation
s, can we add a set of asynchronous methods specifically for loading.lottie
files? From there the user could access any of the animations included in the file.
This will also need to include snapshot tests that render animations from .lottie
files, and the code will need to be formatted according to Airbnb's Swift style guide (you can run bundle exec rake format:swift
to do this automatically).
…emp files from filesystem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Mostly minor comments. I agree that embedding the pieces of functionality from ZIPFoundation that we need as source is the best approach here, thanks for slimming it down to the bare essentials.
I still think the DotLottieFile
initializer / load
/ decompress
functions should be marked as async
so they can't be used directly from the main thread. Thoughts?
We also need some snapshot tests for .lottie
files. Could you add a few of these to Tests/Samples
and make sure SnapshotTests
is capturing snapshots of them? After running the tests this should result in image files for each .lottie
file being included in the repo.
@@ -157,4 +157,7 @@ public final class LottieAnimation: Codable, DictionaryInitializable { | |||
/// Markers | |||
let markers: [Marker]? | |||
let markerMap: [String: Marker]? | |||
|
|||
/// DotLottie configuration to setup the player | |||
var dotLottieConfiguration: DotLottieConfiguration? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have this configuration in a separate dictionary inside DotLottieFile and then besides searching for the animation with id, also search for the configuration with id.
That sounds reasonable, I think this would be better
Co-authored-by: Cal Stephens <cal@calstephens.tech>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
Currently there is issue when // 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, could you file an issue and ideally also provide a sample project that reproduces the issue? |
Thanks, I prepared a PR here: #1802 Sample project creation might take me a while due to busy schedule, my apologies. I believe using
|
@calda |
Helpful, thanks! |
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:
Changes