Browse Source

Choose to recreate animated image

The animated image might be loaded in different options. Try to reload the representation
onevcat 3 years ago
parent
commit
c5236b6ffa
1 changed files with 10 additions and 2 deletions
  1. 10 2
      Sources/General/KingfisherManager.swift

+ 10 - 2
Sources/General/KingfisherManager.swift

@@ -521,10 +521,18 @@ public class KingfisherManager {
                     result.match(
                         onSuccess: { cacheResult in
                             let value: Result<RetrieveImageResult, KingfisherError>
-                            if let image = cacheResult.image {
+                            if var image = cacheResult.image {
+                                if image.kf.imageFrameCount != nil && image.kf.imageFrameCount != 1, let data = image.kf.animatedImageData {
+                                    // Always recreate animated image representation since it is possible to be loaded in different options.
+                                    // https://github.com/onevcat/Kingfisher/issues/1923
+                                    image = KingfisherWrapper.animatedImage(data: data, options: options.imageCreatingOptions) ?? .init()
+                                }
+                                if let modifier = options.imageModifier {
+                                    image = modifier.modify(image)
+                                }
                                 value = result.map {
                                     RetrieveImageResult(
-                                        image: options.imageModifier?.modify(image) ?? image,
+                                        image: image,
                                         cacheType: $0.cacheType,
                                         source: source,
                                         originalSource: context.originalSource