Procházet zdrojové kódy

Refactor to modify the task from the binder instead of directly from KFImageRenderer, aligning with the rest of the code style.

Alex Vaiman před 2 roky
rodič
revize
df8c264c41

+ 6 - 0
Sources/SwiftUI/ImageBinder.swift

@@ -145,6 +145,12 @@ extension KFImage {
             loading = false
         }
         
+        /// Restores the download task priority to default if it is in progress.
+        func restorePriorityOnAppear() {
+            guard let downloadTask = downloadTask, loading == true else { return }
+            downloadTask.sessionTask.task.priority = URLSessionTask.defaultPriority
+        }
+        
         /// Reduce the download task priority if it is in progress.
         func reducePriorityOnDisappear() {
             guard let downloadTask = downloadTask, loading == true else { return }

+ 1 - 1
Sources/SwiftUI/KFImageRenderer.swift

@@ -60,7 +60,7 @@ struct KFImageRenderer<HoldingView> : View where HoldingView: KFImageHoldingView
                         binder.start(context: context)
                     } else {
                         if context.reducePriorityOnDisappear {
-                            binder.downloadTask?.sessionTask.task.priority = URLSessionTask.defaultPriority
+                            binder.restorePriorityOnAppear()
                         }
                     }
                 }