Explorar el Código

Mark some useful property/method public in Animator

onevcat hace 5 años
padre
commit
1da4f6be98
Se han modificado 1 ficheros con 24 adiciones y 15 borrados
  1. 24 15
      Sources/Views/AnimatedImageView.swift

+ 24 - 15
Sources/Views/AnimatedImageView.swift

@@ -154,11 +154,11 @@ open class AnimatedImageView: UIImageView {
 
     /// Delegate of this `AnimatedImageView` object. See `AnimatedImageViewDelegate` protocol for more.
     public weak var delegate: AnimatedImageViewDelegate?
-    
-    // MARK: - Private property
-    /// `Animator` instance that holds the frames of a specific image in memory.
-    private var animator: Animator?
 
+    /// The `Animator` instance that holds the frames of a specific image in memory.
+    public private(set) var animator: Animator?
+
+    // MARK: - Private property
     // Dispatch queue used for preloading images.
     private lazy var preloadQueue: DispatchQueue = {
         return DispatchQueue(label: "com.onevcat.Kingfisher.Animator.preloadQueue")
@@ -353,9 +353,14 @@ extension AnimatedImageView {
 extension AnimatedImageView {
 
     // MARK: - Animator
-    class Animator {
+
+    /// An animator which used to drive the data behind `AnimatedImageView`.
+    public class Animator {
         private let size: CGSize
-        private let maxFrameCount: Int
+
+        /// The maximum count of image frames that needs preload.
+        public let maxFrameCount: Int
+
         private let imageSource: CGImageSource
         private let maxRepeatCount: RepeatCount
 
@@ -376,18 +381,18 @@ extension AnimatedImageView {
         // Total duration of one animation loop
         var loopDuration: TimeInterval = 0
 
-        // Current active frame image
-        var currentFrameImage: UIImage? {
+        /// The image of the current frame.
+        public var currentFrameImage: UIImage? {
             return frame(at: currentFrameIndex)
         }
 
-        // Current active frame duration
-        var currentFrameDuration: TimeInterval {
+        /// The duration of the current active frame duration.
+        public var currentFrameDuration: TimeInterval {
             return duration(at: currentFrameIndex)
         }
 
-        // The index of the current GIF frame.
-        var currentFrameIndex = 0 {
+        /// The index of the current animation frame.
+        public internal(set) var currentFrameIndex = 0 {
             didSet {
                 previousFrameIndex = oldValue
             }
@@ -412,7 +417,8 @@ extension AnimatedImageView {
             }
         }
 
-        var isLastFrame: Bool {
+        /// Whether the current frame is the last frame or not in the animation sequence.
+        public var isLastFrame: Bool {
             return currentFrameIndex == frameCount - 1
         }
 
@@ -448,11 +454,14 @@ extension AnimatedImageView {
             self.preloadQueue = preloadQueue
         }
 
-        func frame(at index: Int) -> KFCrossPlatformImage? {
+        /// Gets the image frame of a given index.
+        /// - Parameter index: The index of desired image.
+        /// - Returns: The decoded image at the frame. `nil` if the index is out of bound or the image is not yet loaded.
+        public func frame(at index: Int) -> KFCrossPlatformImage? {
             return animatedFrames[index]?.image
         }
 
-        func duration(at index: Int) -> TimeInterval {
+        public func duration(at index: Int) -> TimeInterval {
             return animatedFrames[index]?.duration  ?? .infinity
         }