This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
598 additions
and
250 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// LRUDotLottieCache.swift | ||
// Lottie | ||
// | ||
// Created by Evandro Hoffmann on 20/10/22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A DotLottie Cache that will store lottie files up to `cacheSize`. | ||
/// | ||
/// Once `cacheSize` is reached, the least recently used lottie will be ejected. | ||
/// The default size of the cache is 100. | ||
public class DotLottieCache: DotLottieCacheProvider { | ||
|
||
// MARK: Lifecycle | ||
|
||
public init() { | ||
cache.countLimit = Self.defaultCacheCountLimit | ||
} | ||
|
||
// MARK: Public | ||
|
||
/// The global shared Cache. | ||
public static let sharedCache = DotLottieCache() | ||
|
||
/// The size of the cache. | ||
public var cacheSize = defaultCacheCountLimit { | ||
didSet { | ||
cache.countLimit = cacheSize | ||
} | ||
} | ||
|
||
/// Clears the Cache. | ||
public func clearCache() { | ||
cache.removeAllObjects() | ||
} | ||
|
||
public func file(forKey key: String) -> DotLottieFile? { | ||
cache.object(forKey: key as NSString) | ||
} | ||
|
||
public func setFile(_ lottie: DotLottieFile, forKey key: String) { | ||
cache.setObject(lottie, forKey: key as NSString) | ||
} | ||
|
||
// MARK: Private | ||
|
||
private static let defaultCacheCountLimit = 100 | ||
|
||
private var cache = NSCache<NSString, DotLottieFile>() | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// DotLottieCacheProvider.swift | ||
// Lottie | ||
// | ||
// Created by Evandro Hoffmann on 20/10/22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// `DotLottieCacheProvider` is a protocol that describes a DotLottie Cache. | ||
/// DotLottie Cache is used when loading `DotLottie` models. Using a DotLottie Cache | ||
/// can increase performance when loading an animation multiple times. | ||
/// | ||
/// Lottie comes with a prebuilt LRU DotLottie Cache. | ||
public protocol DotLottieCacheProvider { | ||
|
||
func file(forKey: String) -> DotLottieFile? | ||
|
||
func setFile(_ lottie: DotLottieFile, forKey: String) | ||
|
||
func clearCache() | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DotLottieSettings.swift | ||
// Lottie | ||
// | ||
// Created by Evandro Hoffmann on 19/10/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct DotLottieConfiguration { | ||
public var id: String | ||
public var imagesUrl: URL? | ||
public var loop: Bool | ||
public var speed: Double | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.