@@ -10,13 +10,14 @@ import SwiftUI
10
10
import SDWebImage
11
11
12
12
class 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
17
16
18
17
var manager = SDWebImageManager . shared
19
18
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
20
21
21
22
var url : URL ?
22
23
var options : SDWebImageOptions
@@ -35,7 +36,6 @@ class ImageManager : ObservableObject {
35
36
if currentOperation != nil {
36
37
return
37
38
}
38
- self . image = nil
39
39
self . isLoading = true
40
40
currentOperation = manager. loadImage ( with: url, options: options, context: context, progress: { [ weak self] ( receivedSize, expectedSize, _) in
41
41
guard let self = self else {
@@ -55,6 +55,13 @@ class ImageManager : ObservableObject {
55
55
guard let self = self else {
56
56
return
57
57
}
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
+ }
58
65
if let image = image {
59
66
self . image = image
60
67
}
@@ -63,6 +70,7 @@ class ImageManager : ObservableObject {
63
70
self . isLoading = false
64
71
self . progress = 1
65
72
if let image = image {
73
+ self . isFinished = true
66
74
self . successBlock ? ( image, cacheType)
67
75
} else {
68
76
self . failureBlock ? ( error ?? NSError ( ) )
0 commit comments