@@ -12,11 +12,6 @@ import SDWebImage
12
12
import SDWebImageSwiftUIObjC
13
13
#endif
14
14
15
- // Data Binding Object
16
- final class AnimatedImageModel : ObservableObject {
17
- @Published var image : PlatformImage ?
18
- }
19
-
20
15
// Convenient
21
16
#if os(watchOS)
22
17
public typealias AnimatedImageViewWrapper = SDAnimatedImageInterface
@@ -39,10 +34,9 @@ public final class AnimatedImageCoordinator: NSObject {
39
34
40
35
// View
41
36
public struct AnimatedImage : PlatformViewRepresentable {
42
- @ObservedObject var imageModel = AnimatedImageModel ( )
43
-
44
37
// Options
45
38
var url : URL ?
39
+ @State var image : PlatformImage ?
46
40
var webOptions : SDWebImageOptions = [ ]
47
41
var webContext : [ SDWebImageContextOption : Any ] ? = nil
48
42
@@ -84,11 +78,6 @@ public struct AnimatedImage : PlatformViewRepresentable {
84
78
/// True to start animation, false to stop animation.
85
79
@Binding public var isAnimating : Bool
86
80
87
- /// Current loaded image, may be `SDAnimatedImage` type
88
- public var image : PlatformImage ? {
89
- imageModel. image
90
- }
91
-
92
81
/// Create an animated image with url, placeholder, custom options and context.
93
82
/// - Parameter url: The image url
94
83
/// - Parameter placeholder: The placeholder image to show during loading
@@ -131,7 +120,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
131
120
#else
132
121
let image = SDAnimatedImage ( named: name, in: bundle, compatibleWith: nil )
133
122
#endif
134
- self . imageModel . image = image
123
+ self . image = image
135
124
}
136
125
137
126
/// Create an animated image with data and scale.
@@ -148,7 +137,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
148
137
public init ( data: Data , scale: CGFloat = 0 , isAnimating: Binding < Bool > ) {
149
138
self . _isAnimating = isAnimating
150
139
let image = SDAnimatedImage ( data: data, scale: scale)
151
- self . imageModel . image = image
140
+ self . image = image
152
141
}
153
142
154
143
#if os(macOS)
@@ -212,8 +201,10 @@ public struct AnimatedImage : PlatformViewRepresentable {
212
201
view. wrapped. sd_setImage ( with: url, placeholderImage: placeholder, options: webOptions, context: webContext, progress: { ( receivedSize, expectedSize, _) in
213
202
self . progressBlock ? ( receivedSize, expectedSize)
214
203
} ) { ( image, error, cacheType, _) in
204
+ DispatchQueue . main. async {
205
+ self . image = image
206
+ }
215
207
if let image = image {
216
- self . imageModel. image = image
217
208
self . successBlock ? ( image, cacheType)
218
209
} else {
219
210
self . failureBlock ? ( error ?? NSError ( ) )
@@ -235,7 +226,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
235
226
view. wrapped. animates = true
236
227
#endif
237
228
238
- if let image = self . imageModel . image {
229
+ if let image = self . image {
239
230
#if os(watchOS)
240
231
view. wrapped. setImage ( image)
241
232
#else
@@ -349,7 +340,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
349
340
#endif
350
341
351
342
// Animated Image does not support resizing mode and rendering mode
352
- if let image = self . imageModel . image, !image. sd_isAnimated, !image. conforms ( to: SDAnimatedImageProtocol . self) {
343
+ if let image = self . image, !image. sd_isAnimated, !image. conforms ( to: SDAnimatedImageProtocol . self) {
353
344
var image = image
354
345
// ResizingMode
355
346
if let resizingMode = self . resizingMode {
0 commit comments