@@ -20,6 +20,12 @@ final class AnimatedImageModel : ObservableObject {
20
20
@Published var progressBlock : ( ( Int , Int ) -> Void ) ?
21
21
}
22
22
23
+ // Coordinator Life Cycle Binding Object
24
+ final class AnimatedImageCoordinator : ObservableObject {
25
+ @Published var viewCreateBlock : ( ( PlatformView ) -> Void ) ?
26
+ @Published var viewUpdateBlock : ( ( PlatformView ) -> Void ) ?
27
+ }
28
+
23
29
// Layout Binding Object
24
30
final class AnimatedImageLayout : ObservableObject {
25
31
@Published var contentMode : ContentMode = . fill
@@ -58,6 +64,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
58
64
@ObservedObject var imageModel = AnimatedImageModel ( )
59
65
@ObservedObject var imageLayout = AnimatedImageLayout ( )
60
66
@ObservedObject var imageConfiguration = AnimatedImageConfiguration ( )
67
+ @ObservedObject var imageCoordinator = AnimatedImageCoordinator ( )
61
68
62
69
var url : URL ?
63
70
var placeholder : PlatformImage ?
@@ -196,7 +203,11 @@ public struct AnimatedImage : PlatformViewRepresentable {
196
203
}
197
204
198
205
func makeView( context: PlatformViewRepresentableContext < AnimatedImage > ) -> AnimatedImageViewWrapper {
199
- AnimatedImageViewWrapper ( )
206
+ let view = AnimatedImageViewWrapper ( )
207
+ if let viewCreateBlock = imageCoordinator. viewCreateBlock {
208
+ viewCreateBlock ( view)
209
+ }
210
+ return view
200
211
}
201
212
202
213
func updateView( _ view: AnimatedImageViewWrapper , context: PlatformViewRepresentableContext < AnimatedImage > ) {
@@ -238,6 +249,9 @@ public struct AnimatedImage : PlatformViewRepresentable {
238
249
239
250
configureView ( view, context: context)
240
251
layoutView ( view, context: context)
252
+ if let viewUpdateBlock = imageCoordinator. viewUpdateBlock {
253
+ viewUpdateBlock ( view)
254
+ }
241
255
}
242
256
243
257
static func dismantleView( _ view: AnimatedImageViewWrapper , coordinator: ( ) ) {
@@ -554,6 +568,26 @@ extension AnimatedImage {
554
568
}
555
569
}
556
570
571
+ // View Coordinator Handler
572
+ extension AnimatedImage {
573
+
574
+ /// Provide the action when view representable create the native view.
575
+ /// - Parameter action: The action to perform. The first arg is the native view.
576
+ /// - Returns: A view that triggers `action` when view representable create the native view.
577
+ public func onViewCreate( perform action: ( ( PlatformView ) -> Void ) ? = nil ) -> AnimatedImage {
578
+ imageCoordinator. viewCreateBlock = action
579
+ return self
580
+ }
581
+
582
+ /// Provide the action when view representable update the native view.
583
+ /// - Parameter action: The action to perform. The first arg is the native view.
584
+ /// - Returns: A view that triggers `action` when view representable update the native view.
585
+ public func onViewUpdate( perform action: ( ( PlatformView ) -> Void ) ? = nil ) -> AnimatedImage {
586
+ imageCoordinator. viewUpdateBlock = action
587
+ return self
588
+ }
589
+ }
590
+
557
591
#if os(macOS) || os(iOS) || os(tvOS)
558
592
// Web Image convenience
559
593
extension AnimatedImage {
0 commit comments