Răsfoiți Sursa

Merge pull request #1789 from AttilaTheFun/master

Expose AnimatedImageView fields to allow consumers to observe GIF progress
Wei Wang 4 ani în urmă
părinte
comite
21927f4c53

+ 3 - 3
Sources/Image/GIFAnimatedImage.swift

@@ -70,7 +70,7 @@ public struct ImageCreatingOptions {
 
 // Represents the decoding for a GIF image. This class extracts frames from an `imageSource`, then
 // hold the images for later use.
-class GIFAnimatedImage {
+public class GIFAnimatedImage {
     let images: [KFCrossPlatformImage]
     let duration: TimeInterval
     
@@ -98,7 +98,7 @@ class GIFAnimatedImage {
     }
     
     // Calculates frame duration for a gif frame out of the kCGImagePropertyGIFDictionary dictionary.
-    static func getFrameDuration(from gifInfo: [String: Any]?) -> TimeInterval {
+    public static func getFrameDuration(from gifInfo: [String: Any]?) -> TimeInterval {
         let defaultFrameDuration = 0.1
         guard let gifInfo = gifInfo else { return defaultFrameDuration }
         
@@ -111,7 +111,7 @@ class GIFAnimatedImage {
     }
 
     // Calculates frame duration at a specific index for a gif from an `imageSource`.
-    static func getFrameDuration(from imageSource: CGImageSource, at index: Int) -> TimeInterval {
+    public static func getFrameDuration(from imageSource: CGImageSource, at index: Int) -> TimeInterval {
         guard let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, index, nil)
             as? [String: Any] else { return 0.0 }
 

+ 1 - 1
Sources/Image/Image.swift

@@ -90,7 +90,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
     var duration: TimeInterval { return base.duration }
     var size: CGSize { return base.size }
     
-    private(set) var imageSource: CGImageSource? {
+    public private(set) var imageSource: CGImageSource? {
         get { return getAssociatedObject(base, &imageSourceKey) }
         set { setRetainedAssociatedObject(base, &imageSourceKey, newValue) }
     }

+ 7 - 0
Sources/Views/AnimatedImageView.swift

@@ -573,12 +573,19 @@ extension AnimatedImageView {
         }
 
         private func incrementCurrentFrameIndex() {
+            let wasLastFrame = isLastFrame
             currentFrameIndex = increment(frameIndex: currentFrameIndex)
             if isLastFrame {
                 currentRepeatCount += 1
                 if isReachMaxRepeatCount {
                     isFinished = true
+
+                    // Notify the delegate here because the animation is stopping.
+                    delegate?.animator(self, didPlayAnimationLoops: currentRepeatCount)
                 }
+            } else if wasLastFrame {
+
+                // Notify the delegate that the loop completed
                 delegate?.animator(self, didPlayAnimationLoops: currentRepeatCount)
             }
         }