Browse Source

No need to use handler in animated image view frame checking

onevcat 2 years ago
parent
commit
84ce3a7c35
2 changed files with 7 additions and 8 deletions
  1. 2 1
      Sources/Networking/RedirectHandler.swift
  2. 5 7
      Sources/Views/AnimatedImageView.swift

+ 2 - 1
Sources/Networking/RedirectHandler.swift

@@ -30,6 +30,7 @@ import Foundation
 public protocol ImageDownloadRedirectHandler {
 
     /// The `ImageDownloadRedirectHandler` contained will be used to change the request before redirection.
+    /// 
     /// This is the posibility you can modify the image download request during redirection. You can modify the
     /// request for some customizing purpose, such as adding auth token to the header, do basic HTTP auth or
     /// something like url mapping.
@@ -43,7 +44,7 @@ public protocol ImageDownloadRedirectHandler {
     ///   - task: The current `SessionDataTask` which triggers this redirect.
     ///   - response: The response received during redirection.
     ///   - newRequest: The request for redirection which can be modified.
-    ///   - completionHandler: A closure for being called with modified request.
+    /// - Returns: The modified requst.
     func handleHTTPRedirection(
         for task: SessionDataTask,
         response: HTTPURLResponse,

+ 5 - 7
Sources/Views/AnimatedImageView.swift

@@ -325,10 +325,8 @@ open class AnimatedImageView: UIImageView {
             duration = 1.0 / TimeInterval(preferredFramesPerSecond)
         }
 
-        animator.shouldChangeFrame(with: duration) { [weak self] hasNewFrame in
-            if hasNewFrame {
-                self?.layer.setNeedsDisplay()
-            }
+        if animator.shouldChangeFrame(with: duration) {
+            layer.setNeedsDisplay()
         }
     }
 }
@@ -545,15 +543,15 @@ extension AnimatedImageView {
             }
         }
 
-        func shouldChangeFrame(with duration: CFTimeInterval, handler: (Bool) -> Void) {
+        func shouldChangeFrame(with duration: CFTimeInterval) -> Bool {
             incrementTimeSinceLastFrameChange(with: duration)
 
             if currentFrameDuration > timeSinceLastFrameChange {
-                handler(false)
+                return false
             } else {
                 resetTimeSinceLastFrameChange()
                 incrementCurrentFrameIndex()
-                handler(true)
+                return true
             }
         }