Skip to content
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

add a switch to ignore internal image cache #2171

Merged
merged 7 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private final class CachedImageProvider: AnimationImageProvider {
// MARK: Public

public func imageForAsset(asset: ImageAsset) -> CGImage? {
if let image = imageCache.object(forKey: asset.id as NSString) {
if imageProvider.cacheEligible, let image = imageCache.object(forKey: asset.id as NSString) {
calda marked this conversation as resolved.
Show resolved Hide resolved
return image
}
if let image = imageProvider.imageForAsset(asset: asset) {
Expand Down
14 changes: 14 additions & 0 deletions Sources/Public/ImageProvider/AnimationImageProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import CoreGraphics
import Foundation

// MARK: - AnimationImageProvider

/// Image provider is a protocol that is used to supply images to `LottieAnimationView`.
///
/// Some animations require a reference to an image. The image provider loads and
Expand All @@ -17,5 +19,17 @@ import Foundation
/// Additionally custom Image Providers can be made to load images from a URL,
/// or to Cache images.
public protocol AnimationImageProvider {

/// Whether or not the resulting image of this image provider can be cached by Lottie. Defaults to true.
/// If true, Lottie may internally cache the result of `imageForAsset`
var cacheEligible: Bool { get }

/// The image to display for the given `ImageAsset` defined in the `LottieAnimation` JSON file.
func imageForAsset(asset: ImageAsset) -> CGImage?
calda marked this conversation as resolved.
Show resolved Hide resolved
}

extension AnimationImageProvider {
public var cacheEligible: Bool {
true
}
}
Loading