Procházet zdrojové kódy

Use parsed option for image binder

onevcat před 5 roky
rodič
revize
6d3bd39272

+ 17 - 1
Sources/General/KingfisherManager.swift

@@ -189,7 +189,23 @@ public class KingfisherManager {
         completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
     {
         let options = currentDefaultOptions + (options ?? .empty)
-        var info = KingfisherParsedOptionsInfo(options)
+        let info = KingfisherParsedOptionsInfo(options)
+        return retrieveImage(
+            with: source,
+            options: info,
+            progressBlock: progressBlock,
+            downloadTaskUpdated: downloadTaskUpdated,
+            completionHandler: completionHandler)
+    }
+
+    func retrieveImage(
+        with source: Source,
+        options: KingfisherParsedOptionsInfo,
+        progressBlock: DownloadProgressBlock? = nil,
+        downloadTaskUpdated: DownloadTaskUpdatedBlock? = nil,
+        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?
+    {
+        var info = options
         if let block = progressBlock {
             info.onDataReceived = (info.onDataReceived ?? []) + [ImageLoadingProgressSideEffect(block)]
         }

+ 6 - 2
Sources/SwiftUI/ImageBinder.swift

@@ -36,7 +36,7 @@ extension KFImage {
     public class ImageBinder: ObservableObject {
 
         let source: Source?
-        let options: KingfisherOptionsInfo?
+        private var options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions)
 
         var downloadTask: DownloadTask?
 
@@ -54,7 +54,11 @@ extension KFImage {
             self.source = source
             // The refreshing of `KFImage` would happen much more frequently then an `UIImageView`, even as a
             // "side-effect". To prevent unintended flickering, add `.loadDiskFileSynchronously` as a default.
-            self.options = (options ?? []) + [.loadDiskFileSynchronously]
+            self.options = KingfisherParsedOptionsInfo(
+                KingfisherManager.shared.defaultOptions +
+                (options ?? []) +
+                [.loadDiskFileSynchronously]
+            )
             self.isLoaded = isLoaded
             self.image = nil
         }

+ 0 - 1
Sources/SwiftUI/KFImage.swift

@@ -67,7 +67,6 @@ public struct KFImage: SwiftUI.View {
     public init(source: Source?, options: KingfisherOptionsInfo? = nil, isLoaded: Binding<Bool> = .constant(false)) {
         binder = ImageBinder(source: source, options: options, isLoaded: isLoaded)
         configurations = []
-        binder.start()
     }
 
     /// Creates a Kingfisher compatible image view to load image from the given `Source`.