@@ -45,29 +45,29 @@ public struct UIKitIntrospectionView<TargetViewType: UIView>: UIViewRepresentabl
45
45
self . customize = customize
46
46
}
47
47
48
+ /// When `makeUIView` and `updateUIView` are called, the Introspection view is not yet in the UIKit hierarchy.
49
+ /// At this point, `introspectionView.superview.superview` is nil and we can't access the target UIKit view.
50
+ /// To workaround this, we wait until the runloop is done inserting the introspection view in the hierarchy, then run the selector.
51
+ /// Finding the target view fails silently if the selector yields no result. This happens when the introspection view gets
52
+ /// removed from the hierarchy.
48
53
public func makeUIView( context: UIViewRepresentableContext < UIKitIntrospectionView > ) -> IntrospectionUIView {
49
54
let view = IntrospectionUIView ( )
50
55
view. accessibilityLabel = " IntrospectionUIView< \( TargetViewType . self) > "
51
- return view
52
- }
53
-
54
- /// When `updateUiView` is called after creating the Introspection view, it is not yet in the UIKit hierarchy.
55
- /// At this point, `introspectionView.superview.superview` is nil and we can't access the target UIKit view.
56
- /// To workaround this, we wait until the runloop is done inserting the introspection view in the hierarchy, then run the selector.
57
- /// Finding the target view fails silently if the selector yield no result. This happens when `updateUIView`
58
- /// gets called when the introspection view gets removed from the hierarchy.
59
- public func updateUIView(
60
- _ uiView: IntrospectionUIView ,
61
- context: UIViewRepresentableContext < UIKitIntrospectionView >
62
- ) {
63
- uiView. moveToWindowHandler = {
56
+ view. moveToWindowHandler = { [ weak view] in
57
+ guard let view = view else { return }
64
58
DispatchQueue . main. async {
65
- guard let targetView = self . selector ( uiView ) else {
59
+ guard let targetView = self . selector ( view ) else {
66
60
return
67
61
}
68
62
self . customize ( targetView)
69
63
}
70
64
}
65
+ return view
71
66
}
67
+
68
+ public func updateUIView(
69
+ _ uiView: IntrospectionUIView ,
70
+ context: UIViewRepresentableContext < UIKitIntrospectionView >
71
+ ) { }
72
72
}
73
73
#endif
0 commit comments