@@ -10,13 +10,14 @@ import SwiftUI
1010import SDWebImage
1111
1212class ImageManager : ObservableObject {
13- @Published var image : PlatformImage ?
14- @Published var isLoading : Bool = false
15- @Published var isIncremental : Bool = false
16- @Published var progress : CGFloat = 0
13+ @Published var image : PlatformImage ? // loaded image, note when progressive loading, this will published multiple times with different partial image
14+ @Published var isLoading : Bool = false // whether network is loading or cache is querying
15+ @Published var progress : CGFloat = 0 // network progress
1716
1817 var manager = SDWebImageManager . shared
1918 weak var currentOperation : SDWebImageOperation ? = nil
19+ var isFinished : Bool = false // true means request end, load() do nothing
20+ var isIncremental : Bool = false // true means during incremental loading
2021
2122 var url : URL ?
2223 var options : SDWebImageOptions
@@ -35,7 +36,6 @@ class ImageManager : ObservableObject {
3536 if currentOperation != nil {
3637 return
3738 }
38- self . image = nil
3939 self . isLoading = true
4040 currentOperation = manager. loadImage ( with: url, options: options, context: context, progress: { [ weak self] ( receivedSize, expectedSize, _) in
4141 guard let self = self else {
@@ -55,6 +55,13 @@ class ImageManager : ObservableObject {
5555 guard let self = self else {
5656 return
5757 }
58+ if let error = error as? SDWebImageError , error. code == . cancelled {
59+ // Ignore user cancelled
60+ // There are race condition when quick scroll
61+ // Indicator modifier disapper and trigger `WebImage.body`
62+ // So previous View struct call `onDisappear` and cancel the currentOperation
63+ return
64+ }
5865 if let image = image {
5966 self . image = image
6067 }
@@ -63,6 +70,7 @@ class ImageManager : ObservableObject {
6370 self . isLoading = false
6471 self . progress = 1
6572 if let image = image {
73+ self . isFinished = true
6674 self . successBlock ? ( image, cacheType)
6775 } else {
6876 self . failureBlock ? ( error ?? NSError ( ) )
0 commit comments