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
// | |
// PagedIndexViewModifier.swift | |
// | |
// Copyright© 2023 ApiumHub | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is |
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
import Lottie // We need it because of the Animation Model | |
protocol LottieFileProviding: AnyObject { | |
func animation(forKey: String) -> Animation? | |
func setAnimationData(_ data: Data, forKey: String) | |
} | |
final class LottieFileProvider: LottieFileProviding { | |
static var shared = LottieFileProvider() | |
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
//////////// AnimationPublic.swift | |
static func loadedFrom(url: URL, | |
closure: @escaping Animation.DownloadClosure, | |
animationCache: AnimationCacheProvider?) { | |
/// 1 | |
if let animationCache = animationCache, let animation = animationCache.animation(forKey: url.absoluteString) { | |
closure(animation) | |
} else { | |
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in |
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
extension AnimationView { | |
func setAnimation(from url: URL?, | |
cacheProvider: LottieFileProviding = LottieFileProvider.shared, | |
afterSetCompletion: @escaping (AnimationView) -> Void) { | |
guard let url = url else { return } | |
/// 1 | |
if let animation = cacheProvider.animation(forKey: url.absoluteString) { | |
self.animation = animation | |
afterSetCompletion(self) |
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
import UIKit | |
import Lottie | |
final class AnimationContainerView: UIView { | |
// MARK: - Initializers | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setupView() | |
setupConstraints() | |
} |
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, |