@@ -21,12 +21,10 @@ public final class ImageManager : ObservableObject {
21
21
@Published public var cacheType : SDImageCacheType = . none
22
22
/// loading error, you can grab the error code and reason listed in `SDWebImageErrorDomain`, to provide a user interface about the error reason
23
23
@Published public var error : Error ?
24
- /// whether network is loading or cache is querying, should only be used for indicator binding
25
- @Published public var isLoading : Bool = false
26
- /// network progress, should only be used for indicator binding
27
- @Published public var progress : Double = 0
28
24
/// true means during incremental loading
29
25
@Published public var isIncremental : Bool = false
26
+ /// A observed object to pass through the image manager loading status to indicator
27
+ @Published public var indicatorStatus = IndicatorStatus ( )
30
28
31
29
weak var currentOperation : SDWebImageOperation ? = nil
32
30
@@ -50,7 +48,7 @@ public final class ImageManager : ObservableObject {
50
48
if currentOperation != nil {
51
49
return
52
50
}
53
- self . isLoading = true
51
+ self . indicatorStatus . isLoading = true
54
52
currentOperation = manager. loadImage ( with: url, options: options, context: context, progress: { [ weak self] ( receivedSize, expectedSize, _) in
55
53
guard let self = self else {
56
54
return
@@ -62,7 +60,7 @@ public final class ImageManager : ObservableObject {
62
60
progress = 0
63
61
}
64
62
DispatchQueue . main. async {
65
- self . progress = progress
63
+ self . indicatorStatus . progress = progress
66
64
}
67
65
self . progressBlock ? ( receivedSize, expectedSize)
68
66
} ) { [ weak self] ( image, data, error, cacheType, finished, _) in
@@ -82,8 +80,8 @@ public final class ImageManager : ObservableObject {
82
80
if finished {
83
81
self . imageData = data
84
82
self . cacheType = cacheType
85
- self . isLoading = false
86
- self . progress = 1
83
+ self . indicatorStatus . isLoading = false
84
+ self . indicatorStatus . progress = 1
87
85
if let image = image {
88
86
self . successBlock ? ( image, data, cacheType)
89
87
} else {
@@ -98,8 +96,8 @@ public final class ImageManager : ObservableObject {
98
96
if let operation = currentOperation {
99
97
operation. cancel ( )
100
98
currentOperation = nil
101
- isLoading = false
102
99
}
100
+ indicatorStatus. isLoading = false
103
101
}
104
102
105
103
}
0 commit comments