diff --git a/Sources/Private/MainThread/LayerContainers/Utility/CachedImageProvider.swift b/Sources/Private/MainThread/LayerContainers/Utility/CachedImageProvider.swift index d2fa02cd97..c74355672d 100644 --- a/Sources/Private/MainThread/LayerContainers/Utility/CachedImageProvider.swift +++ b/Sources/Private/MainThread/LayerContainers/Utility/CachedImageProvider.swift @@ -42,6 +42,7 @@ extension AnimationImageProvider { /// It wraps the current provider as image loader, and uses `NSCache` to cache the images for resue. /// The cache will be reset when the `animation` is reset. var cachedImageProvider: AnimationImageProvider { - CachedImageProvider(imageProvider: self) + guard cacheEligible else { return self } + return CachedImageProvider(imageProvider: self) } } diff --git a/Sources/Public/ImageProvider/AnimationImageProvider.swift b/Sources/Public/ImageProvider/AnimationImageProvider.swift index f9358a2f7b..e87083206a 100644 --- a/Sources/Public/ImageProvider/AnimationImageProvider.swift +++ b/Sources/Public/ImageProvider/AnimationImageProvider.swift @@ -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 @@ -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? } + +extension AnimationImageProvider { + public var cacheEligible: Bool { + true + } +}