@@ -15,17 +15,47 @@ import SDWebImage
15
15
@available ( iOS 14 . 0 , OSX 11 . 0 , tvOS 14 . 0 , watchOS 7 . 0 , * )
16
16
public final class ImageManager : ObservableObject {
17
17
/// loaded image, note when progressive loading, this will published multiple times with different partial image
18
- @Published public var image : PlatformImage ?
18
+ public var image : PlatformImage ? {
19
+ didSet {
20
+ DispatchQueue . main. async {
21
+ self . objectWillChange. send ( )
22
+ }
23
+ }
24
+ }
19
25
/// loaded image data, may be nil if hit from memory cache. This will only published once even on incremental image loading
20
- @Published public var imageData : Data ?
26
+ public var imageData : Data ? {
27
+ didSet {
28
+ DispatchQueue . main. async {
29
+ self . objectWillChange. send ( )
30
+ }
31
+ }
32
+ }
21
33
/// loaded image cache type, .none means from network
22
- @Published public var cacheType : SDImageCacheType = . none
34
+ public var cacheType : SDImageCacheType = . none {
35
+ didSet {
36
+ DispatchQueue . main. async {
37
+ self . objectWillChange. send ( )
38
+ }
39
+ }
40
+ }
23
41
/// loading error, you can grab the error code and reason listed in `SDWebImageErrorDomain`, to provide a user interface about the error reason
24
- @Published public var error : Error ?
42
+ public var error : Error ? {
43
+ didSet {
44
+ DispatchQueue . main. async {
45
+ self . objectWillChange. send ( )
46
+ }
47
+ }
48
+ }
25
49
/// true means during incremental loading
26
- @Published public var isIncremental : Bool = false
50
+ public var isIncremental : Bool = false {
51
+ didSet {
52
+ DispatchQueue . main. async {
53
+ self . objectWillChange. send ( )
54
+ }
55
+ }
56
+ }
27
57
/// A observed object to pass through the image manager loading status to indicator
28
- @ Published public var indicatorStatus = IndicatorStatus ( )
58
+ public var indicatorStatus = IndicatorStatus ( )
29
59
30
60
weak var currentOperation : SDWebImageOperation ? = nil
31
61
@@ -51,8 +81,8 @@ public final class ImageManager : ObservableObject {
51
81
return
52
82
}
53
83
currentURL = url
54
- indicatorStatus. isLoading = true
55
- indicatorStatus. progress = 0
84
+ self . indicatorStatus. isLoading = true
85
+ self . indicatorStatus. progress = 0
56
86
currentOperation = manager. loadImage ( with: url, options: options, context: context, progress: { [ weak self] ( receivedSize, expectedSize, _) in
57
87
guard let self = self else {
58
88
return
@@ -63,9 +93,7 @@ public final class ImageManager : ObservableObject {
63
93
} else {
64
94
progress = 0
65
95
}
66
- DispatchQueue . main. async {
67
- self . indicatorStatus. progress = progress
68
- }
96
+ self . indicatorStatus. progress = progress
69
97
self . progressBlock ? ( receivedSize, expectedSize)
70
98
} ) { [ weak self] ( image, data, error, cacheType, finished, _) in
71
99
guard let self = self else {
0 commit comments