Преглед изворни кода

Implement progressive jpeg support in SwiftUI

onevcat пре 11 месеци
родитељ
комит
66fec91402

+ 0 - 9
Sources/General/KF.swift

@@ -409,15 +409,6 @@ extension KF.Builder {
         options.onlyLoadFirstFrame = enabled
         return self
     }
-
-    /// Enables progressive image loading with a specified `ImageProgressive` setting to process the
-    /// progressive JPEG data and display it in a progressive way.
-    /// - Parameter progressive: The progressive settings which is used while loading.
-    /// - Returns: A ``KF/Builder`` with changes applied.
-    public func progressiveJPEG(_ progressive: ImageProgressive? = .init()) -> Self {
-        options.progressiveJPEG = progressive
-        return self
-    }
 }
 
 // MARK: - Deprecated

+ 9 - 0
Sources/General/KFOptionsSetter.swift

@@ -501,6 +501,15 @@ extension KFOptionSetter {
         options.processor = processor
         return self
     }
+    
+    /// Enables progressive image loading with a specified `ImageProgressive` setting to process the
+    /// progressive JPEG data and display it in a progressive way.
+    /// - Parameter progressive: The progressive settings which is used while loading.
+    /// - Returns: A ``KF/Builder`` with changes applied.
+    public func progressiveJPEG(_ progressive: ImageProgressive? = .init()) -> Self {
+        options.progressiveJPEG = progressive
+        return self
+    }
 
     /// Sets an array of image processors for the image task, replacing the current image processor settings.
     ///

+ 3 - 2
Sources/General/KingfisherManager.swift

@@ -250,8 +250,9 @@ public class KingfisherManager: @unchecked Sendable {
     func retrieveImage(
         with source: Source,
         options: KingfisherParsedOptionsInfo,
-        progressBlock: DownloadProgressBlock? = nil,
+        progressBlock: DownloadProgressBlock?,
         downloadTaskUpdated: DownloadTaskUpdatedBlock? = nil,
+        progressiveImageSetter: ((KFCrossPlatformImage?) -> Void)? = nil,
         completionHandler: (@Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
     {
         var info = options
@@ -262,7 +263,7 @@ public class KingfisherManager: @unchecked Sendable {
             with: source,
             options: info,
             downloadTaskUpdated: downloadTaskUpdated,
-            progressiveImageSetter: nil,
+            progressiveImageSetter: progressiveImageSetter,
             completionHandler: completionHandler)
     }
 

+ 6 - 0
Sources/SwiftUI/ImageBinder.swift

@@ -89,6 +89,12 @@ extension KFImage {
                         self.updateProgress(downloaded: size, total: total)
                         context.onProgressDelegate.call((size, total))
                     },
+                    progressiveImageSetter: { image in
+                        CallbackQueueMain.currentOrAsync {
+                            self.markLoaded(sendChangeEvent: true)
+                            self.loadedImage = image
+                        }
+                    },
                     completionHandler: { [weak self] result in
 
                         guard let self else { return }