@@ -31,10 +31,18 @@ final class AnimatedImageLayout : ObservableObject {
31
31
@Published var antialiased : Bool = false
32
32
}
33
33
34
+ // Configuration Binding Object
35
+ final class AnimatedImageConfiguration : ObservableObject {
36
+ @Published var incrementalLoad : Bool ?
37
+ @Published var maxBufferSize : UInt ?
38
+ @Published var customLoopCount : Int ?
39
+ }
40
+
34
41
// View
35
42
public struct AnimatedImage : PlatformViewRepresentable {
36
43
@ObservedObject var imageModel = AnimatedImageModel ( )
37
44
@ObservedObject var imageLayout = AnimatedImageLayout ( )
45
+ @ObservedObject var imageConfiguration = AnimatedImageConfiguration ( )
38
46
39
47
var placeholder : PlatformImage ?
40
48
var webOptions : SDWebImageOptions = [ ]
@@ -82,6 +90,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
82
90
}
83
91
}
84
92
93
+ configureView ( view, context: context)
85
94
layoutView ( view, context: context)
86
95
}
87
96
@@ -190,6 +199,30 @@ public struct AnimatedImage : PlatformViewRepresentable {
190
199
view. setNeedsDisplay ( )
191
200
#endif
192
201
}
202
+
203
+ func configureView( _ view: AnimatedImageViewWrapper , context: PlatformViewRepresentableContext < AnimatedImage > ) {
204
+ // IncrementalLoad
205
+ if let incrementalLoad = imageConfiguration. incrementalLoad {
206
+ view. wrapped. shouldIncrementalLoad = incrementalLoad
207
+ }
208
+
209
+ // MaxBufferSize
210
+ if let maxBufferSize = imageConfiguration. maxBufferSize {
211
+ view. wrapped. maxBufferSize = maxBufferSize
212
+ } else {
213
+ // automatically
214
+ view. wrapped. maxBufferSize = 0
215
+ }
216
+
217
+ // CustomLoopCount
218
+ if let customLoopCount = imageConfiguration. customLoopCount {
219
+ view. wrapped. shouldCustomLoopCount = true
220
+ view. wrapped. animationRepeatCount = customLoopCount
221
+ } else {
222
+ // disable custom loop count
223
+ view. wrapped. shouldCustomLoopCount = false
224
+ }
225
+ }
193
226
}
194
227
195
228
// Layout
@@ -241,6 +274,24 @@ extension AnimatedImage {
241
274
}
242
275
}
243
276
277
+ // AnimatedImage Modifier
278
+ extension AnimatedImage {
279
+ public func customLoopCount( _ loopCount: Int ? ) -> AnimatedImage {
280
+ imageConfiguration. customLoopCount = loopCount
281
+ return self
282
+ }
283
+
284
+ public func maxBufferSize( _ bufferSize: UInt ? ) -> AnimatedImage {
285
+ imageConfiguration. maxBufferSize = bufferSize
286
+ return self
287
+ }
288
+
289
+ public func incrementalLoad( _ incrementalLoad: Bool ) -> AnimatedImage {
290
+ imageConfiguration. incrementalLoad = incrementalLoad
291
+ return self
292
+ }
293
+ }
294
+
244
295
// Completion Handler
245
296
extension AnimatedImage {
246
297
public func onFailure( perform action: ( ( Error ) -> Void ) ? = nil ) -> AnimatedImage {
0 commit comments