Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
[FIX] Renamed lottie files to avoid issues with latest lottie version
Browse files Browse the repository at this point in the history
  • Loading branch information
eharrison committed Dec 8, 2023
1 parent 4821346 commit deced89
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Sources/dotLottieLoader/DotLottieCreator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DotLottieConfiguration.swift
// LottieConfiguration.swift
// Pods
//
// Created by Evandro Harrison Hoffmann on 23/06/2021.
Expand Down
98 changes: 49 additions & 49 deletions Sources/dotLottieLoader/DotLottieLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public class DotLottieLoader {
/// Please use the asynchronous methods whenever possible. This operation will block the Thread it is running in.
///
/// - Parameter filepath: The absolute filepath of the lottie to load. EG "/User/Me/starAnimation.lottie"
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
public static func loadedFrom(
filepath: String,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
-> Result<DotLottieFile, Error>
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
-> Result<LottieFile, Error>
{
/// Check cache for lottie
if
let dotLottieCache = dotLottieCache,
let lottie = dotLottieCache.file(forKey: filepath)
let LottieCache = LottieCache,
let lottie = LottieCache.file(forKey: filepath)
{
return .success(lottie)
}
Expand All @@ -32,8 +32,8 @@ public class DotLottieLoader {
/// Decode the lottie.
let url = URL(fileURLWithPath: filepath)
let data = try Data(contentsOf: url)
let lottie = try DotLottieFile(data: data, filename: url.deletingPathExtension().lastPathComponent)
dotLottieCache?.setFile(lottie, forKey: filepath)
let lottie = try LottieFile(data: data, filename: url.deletingPathExtension().lastPathComponent)
LottieCache?.setFile(lottie, forKey: filepath)
return .success(lottie)
} catch {
/// Decoding Error.
Expand All @@ -47,30 +47,30 @@ public class DotLottieLoader {
/// - Parameter name: The name of the lottie file without the lottie extension. EG "StarAnimation"
/// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
/// - Parameter subdirectory: A subdirectory in the bundle in which the lottie is located. Optional.
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
public static func named(
_ name: String,
bundle: Bundle = Bundle.main,
subdirectory: String? = nil,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
-> Result<DotLottieFile, Error>
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
-> Result<LottieFile, Error>
{
/// Create a cache key for the lottie.
let cacheKey = bundle.bundlePath + (subdirectory ?? "") + "/" + name

/// Check cache for lottie
if
let dotLottieCache = dotLottieCache,
let lottie = dotLottieCache.file(forKey: cacheKey)
let LottieCache = LottieCache,
let lottie = LottieCache.file(forKey: cacheKey)
{
return .success(lottie)
}

do {
/// Decode animation.
let data = try bundle.dotLottieData(name, subdirectory: subdirectory)
let lottie = try DotLottieFile(data: data, filename: name)
dotLottieCache?.setFile(lottie, forKey: cacheKey)
let lottie = try LottieFile(data: data, filename: name)
LottieCache?.setFile(lottie, forKey: cacheKey)
return .success(lottie)
} catch {
/// Decoding error.
Expand All @@ -84,17 +84,17 @@ public class DotLottieLoader {
/// - Parameter name: The name of the lottie file without the lottie extension. EG "StarAnimation"
/// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
/// - Parameter subdirectory: A subdirectory in the bundle in which the lottie is located. Optional.
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
public static func named(
_ name: String,
bundle: Bundle = Bundle.main,
subdirectory: String? = nil,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
async throws -> DotLottieFile
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
async throws -> LottieFile
{
try await withCheckedThrowingContinuation { continuation in
DotLottieLoader.named(name, bundle: bundle, subdirectory: subdirectory, dotLottieCache: dotLottieCache) { result in
DotLottieLoader.named(name, bundle: bundle, subdirectory: subdirectory, LottieCache: LottieCache) { result in
continuation.resume(with: result)
}
}
Expand All @@ -105,23 +105,23 @@ public class DotLottieLoader {
/// - Parameter name: The name of the lottie file without the lottie extension. EG "StarAnimation"
/// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
/// - Parameter subdirectory: A subdirectory in the bundle in which the lottie is located. Optional.
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
/// - Parameter dispatchQueue: A dispatch queue used to load animations. Defaults to `DispatchQueue.global()`. Optional.
/// - Parameter handleResult: A closure to be called when the file has loaded.
public static func named(
_ name: String,
bundle: Bundle = Bundle.main,
subdirectory: String? = nil,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
LottieCache: LottieCacheProvider? = LottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
handleResult: @escaping (Result<LottieFile, Error>) -> Void)
{
dispatchQueue.async {
let result = SynchronouslyBlockingCurrentThread.named(
name,
bundle: bundle,
subdirectory: subdirectory,
dotLottieCache: dotLottieCache)
LottieCache: LottieCache)

DispatchQueue.main.async {
handleResult(result)
Expand All @@ -131,35 +131,35 @@ public class DotLottieLoader {

/// Loads an DotLottie from a specific filepath.
/// - Parameter filepath: The absolute filepath of the lottie to load. EG "/User/Me/starAnimation.lottie"
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
public static func loadedFrom(
filepath: String,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
async throws -> DotLottieFile
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
async throws -> LottieFile
{
try await withCheckedThrowingContinuation { continuation in
DotLottieLoader.loadedFrom(filepath: filepath, dotLottieCache: dotLottieCache) { result in
DotLottieLoader.loadedFrom(filepath: filepath, LottieCache: LottieCache) { result in
continuation.resume(with: result)
}
}
}

/// Loads an DotLottie from a specific filepath.
/// - Parameter filepath: The absolute filepath of the lottie to load. EG "/User/Me/starAnimation.lottie"
/// - Parameter dotLottieCache: A cache for holding loaded lotties. Defaults to `LRUDotLottieCache.sharedCache`. Optional.
/// - Parameter LottieCache: A cache for holding loaded lotties. Defaults to `LRULottieCache.sharedCache`. Optional.
/// - Parameter dispatchQueue: A dispatch queue used to load animations. Defaults to `DispatchQueue.global()`. Optional.
/// - Parameter handleResult: A closure to be called when the file has loaded.
public static func loadedFrom(
filepath: String,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
LottieCache: LottieCacheProvider? = LottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
handleResult: @escaping (Result<LottieFile, Error>) -> Void)
{
dispatchQueue.async {
let result = SynchronouslyBlockingCurrentThread.loadedFrom(
filepath: filepath,
dotLottieCache: dotLottieCache)
LottieCache: LottieCache)

DispatchQueue.main.async {
handleResult(result)
Expand All @@ -170,16 +170,16 @@ public class DotLottieLoader {
/// Loads a DotLottie model from the asset catalog by its name. Returns `nil` if a lottie is not found.
/// - Parameter name: The name of the lottie file in the asset catalog. EG "StarAnimation"
/// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
/// - Parameter dotLottieCache: A cache for holding loaded lottie files. Defaults to `LRUDotLottieCache.sharedCache` Optional.
/// - Parameter LottieCache: A cache for holding loaded lottie files. Defaults to `LRULottieCache.sharedCache` Optional.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
public static func asset(
named name: String,
bundle: Bundle = Bundle.main,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
async throws -> DotLottieFile
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
async throws -> LottieFile
{
try await withCheckedThrowingContinuation { continuation in
DotLottieLoader.asset(named: name, bundle: bundle, dotLottieCache: dotLottieCache) { result in
DotLottieLoader.asset(named: name, bundle: bundle, LottieCache: LottieCache) { result in
continuation.resume(with: result)
}
}
Expand All @@ -188,24 +188,24 @@ public class DotLottieLoader {
/// Loads a DotLottie model from the asset catalog by its name. Returns `nil` if a lottie is not found.
/// - Parameter name: The name of the lottie file in the asset catalog. EG "StarAnimation"
/// - Parameter bundle: The bundle in which the lottie is located. Defaults to `Bundle.main`
/// - Parameter dotLottieCache: A cache for holding loaded lottie files. Defaults to `LRUDotLottieCache.sharedCache` Optional.
/// - Parameter LottieCache: A cache for holding loaded lottie files. Defaults to `LRULottieCache.sharedCache` Optional.
/// - Parameter dispatchQueue: A dispatch queue used to load animations. Defaults to `DispatchQueue.global()`. Optional.
/// - Parameter handleResult: A closure to be called when the file has loaded.
public static func asset(
named name: String,
bundle: Bundle = Bundle.main,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
LottieCache: LottieCacheProvider? = LottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
handleResult: @escaping (Result<LottieFile, Error>) -> Void)
{
dispatchQueue.async {
/// Create a cache key for the lottie.
let cacheKey = bundle.bundlePath + "/" + name

/// Check cache for lottie
if
let dotLottieCache = dotLottieCache,
let lottie = dotLottieCache.file(forKey: cacheKey)
let LottieCache = LottieCache,
let lottie = LottieCache.file(forKey: cacheKey)
{
/// If found, return the lottie.
DispatchQueue.main.async {
Expand All @@ -219,8 +219,8 @@ public class DotLottieLoader {
let data = try Data(assetName: name, in: bundle)

/// Decode lottie.
let lottie = try DotLottieFile(data: data, filename: name)
dotLottieCache?.setFile(lottie, forKey: cacheKey)
let lottie = try LottieFile(data: data, filename: name)
LottieCache?.setFile(lottie, forKey: cacheKey)
DispatchQueue.main.async {
handleResult(.success(lottie))
}
Expand All @@ -241,11 +241,11 @@ public class DotLottieLoader {
public static func loadedFrom(
url: URL,
session: URLSession = .shared,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache)
async throws -> DotLottieFile
LottieCache: LottieCacheProvider? = LottieCache.sharedCache)
async throws -> LottieFile
{
try await withCheckedThrowingContinuation { continuation in
DotLottieLoader.loadedFrom(url: url, session: session, dotLottieCache: dotLottieCache) { result in
DotLottieLoader.loadedFrom(url: url, session: session, LottieCache: LottieCache) { result in
continuation.resume(with: result)
}
}
Expand All @@ -259,10 +259,10 @@ public class DotLottieLoader {
public static func loadedFrom(
url: URL,
session: URLSession = .shared,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
LottieCache: LottieCacheProvider? = LottieCache.sharedCache,
handleResult: @escaping (Result<LottieFile, Error>) -> Void)
{
if let dotLottieCache = dotLottieCache, let lottie = dotLottieCache.file(forKey: url.absoluteString) {
if let LottieCache = LottieCache, let lottie = LottieCache.file(forKey: url.absoluteString) {
handleResult(.success(lottie))
} else {
let task = session.dataTask(with: url) { data, _, error in
Expand All @@ -273,9 +273,9 @@ public class DotLottieLoader {
guard let data = data else {
throw DotLottieError.noDataLoaded
}
let lottie = try DotLottieFile(data: data, filename: url.deletingPathExtension().lastPathComponent)
let lottie = try LottieFile(data: data, filename: url.deletingPathExtension().lastPathComponent)
DispatchQueue.main.async {
dotLottieCache?.setFile(lottie, forKey: url.absoluteString)
LottieCache?.setFile(lottie, forKey: url.absoluteString)
handleResult(.success(lottie))
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/dotLottieLoader/DotLottieUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension URL {
/// Checks if url has been decompressed
public var isLottieFileDecompressed: Bool {
let url = DotLottieUtils.animationsDirectoryURL(for: self)
.appendingPathComponent(DotLottieFile.animationsFolderName)
.appendingPathComponent(LottieFile.animationsFolderName)
var isDirectory: ObjCBool = false
if FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory) {
return isDirectory.boolValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// LRUDotLottieCache.swift
// LRULottieCache.swift
// Lottie
//
// Created by Evandro Hoffmann on 20/10/22.
Expand All @@ -11,7 +11,7 @@ import Foundation
///
/// Once `cacheSize` is reached, the least recently used lottie will be ejected.
/// The default size of the cache is 100.
public class DotLottieCache: DotLottieCacheProvider {
public class LottieCache: LottieCacheProvider {

// MARK: Lifecycle

Expand All @@ -22,7 +22,7 @@ public class DotLottieCache: DotLottieCacheProvider {
// MARK: Public

/// The global shared Cache.
public static let sharedCache = DotLottieCache()
public static let sharedCache = LottieCache()

/// The size of the cache.
public var cacheSize = defaultCacheCountLimit {
Expand All @@ -36,18 +36,18 @@ public class DotLottieCache: DotLottieCacheProvider {
cache.removeAllObjects()
}

public func file(forKey key: String) -> DotLottieFile? {
public func file(forKey key: String) -> LottieFile? {
cache.object(forKey: key as NSString)
}

public func setFile(_ lottie: DotLottieFile, forKey key: String) {
public func setFile(_ lottie: LottieFile, forKey key: String) {
cache.setObject(lottie, forKey: key as NSString)
}

// MARK: Private

private static let defaultCacheCountLimit = 100

private var cache = NSCache<NSString, DotLottieFile>()
private var cache = NSCache<NSString, LottieFile>()

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//
// DotLottieCacheProvider.swift
// LottieCacheProvider.swift
// Lottie
//
// Created by Evandro Hoffmann on 20/10/22.
//

import Foundation

/// `DotLottieCacheProvider` is a protocol that describes a DotLottie Cache.
/// `LottieCacheProvider` 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 {
public protocol LottieCacheProvider {

func file(forKey: String) -> DotLottieFile?
func file(forKey: String) -> LottieFile?

func setFile(_ lottie: DotLottieFile, forKey: String)
func setFile(_ lottie: LottieFile, forKey: String)

func clearCache()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct DotLottieConfiguration {
public struct LottieConfiguration {
public var id: String
public var imagesUrl: URL?
public var loop: Bool
Expand Down
Loading

0 comments on commit deced89

Please sign in to comment.