Last active
May 10, 2021 14:24
-
-
Save Polenoso/f58a1bc33dbf792cfe0f51d5500f971e to your computer and use it in GitHub Desktop.
Lottie Animation From URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Loads a Lottie animation asynchronously from the URL | |
- Parameter url: The url to load the animation from. | |
- Parameter imageProvider: An image provider for the animation's image data. | |
If none is supplied Lottie will search in the main bundle for images. | |
- Parameter closure: A closure to be called when the animation has loaded. | |
*/ | |
convenience init(url: URL, | |
imageProvider: AnimationImageProvider? = nil, | |
closure: @escaping AnimationView.DownloadClosure, | |
animationCache: AnimationCacheProvider? = LRUAnimationCache.sharedCache) { | |
if let animationCache = animationCache, let animation = animationCache.animation(forKey: url.absoluteString) { | |
self.init(animation: animation, imageProvider: imageProvider) | |
closure(nil) | |
} else { | |
self.init(animation: nil, imageProvider: imageProvider) | |
Animation.loadedFrom(url: url, closure: { (animation) in | |
if let animation = animation { | |
self.animation = animation | |
closure(nil) | |
} else { | |
closure(LottieDownloadError.downloadFailed) | |
} | |
}, animationCache: animationCache) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://github.com/airbnb/lottie-ios/blob/fe9ccb33b5f3baf53bb56f11b75950367313201a/lottie-swift/src/Public/Animation/AnimationViewInitializers.swift#L66-L73