File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
SDWebImageSwiftUI/Classes Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -60,9 +60,27 @@ public struct WebImage : View {
60
60
. onDisappear {
61
61
self . imageManager. cancel ( )
62
62
}
63
- // Convert Combine.Publisher to Binding, I think this need a better API from Apple :)
64
- . onReceive ( imageManager. $isLoading) { self . isLoading = $0 }
65
- . onReceive ( imageManager. $progress) { self . progress = $0 }
63
+ // Convert Combine.Publisher to Binding
64
+ . onReceive ( imageManager. $isLoading) { isLoading in
65
+ // only Apple Watch complain that "Modifying state during view update, this will cause undefined behavior."
66
+ // Use dispatch to workaround, Thanks Apple :)
67
+ #if os(watchOS)
68
+ DispatchQueue . main. async {
69
+ self . isLoading = isLoading
70
+ }
71
+ #else
72
+ self . isLoading = isLoading
73
+ #endif
74
+ }
75
+ . onReceive ( imageManager. $progress) { progress in
76
+ #if os(watchOS)
77
+ DispatchQueue . main. async {
78
+ self . progress = progress
79
+ }
80
+ #else
81
+ self . progress = progress
82
+ #endif
83
+ }
66
84
if let indicator = indicator {
67
85
return AnyView (
68
86
ZStack {
You can’t perform that action at this time.
0 commit comments