@@ -12,33 +12,50 @@ public struct IntrospectionScope: OptionSet {
12
12
}
13
13
14
14
extension View {
15
- @ViewBuilder
16
15
public func introspect< SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > (
17
16
_ viewType: SwiftUIViewType ,
18
17
on platforms: ( PlatformViewVersions < SwiftUIViewType , PlatformSpecificEntity > ) ... ,
19
18
scope: IntrospectionScope ? = nil ,
20
19
customize: @escaping ( PlatformSpecificEntity ) -> Void
21
20
) -> some View {
21
+ self . modifier ( IntrospectModifier ( viewType, platforms: platforms, scope: scope, customize: customize) )
22
+ }
23
+ }
24
+
25
+ struct IntrospectModifier < SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > : ViewModifier {
26
+ let id = IntrospectionViewID ( )
27
+ let scope : IntrospectionScope
28
+ let selector : IntrospectionSelector < PlatformSpecificEntity > ?
29
+ let customize : ( PlatformSpecificEntity ) -> Void
30
+
31
+ init (
32
+ _ viewType: SwiftUIViewType ,
33
+ platforms: [ PlatformViewVersions < SwiftUIViewType , PlatformSpecificEntity > ] ,
34
+ scope: IntrospectionScope ? ,
35
+ customize: @escaping ( PlatformSpecificEntity ) -> Void
36
+ ) {
37
+ self . scope = scope ?? viewType. scope
22
38
if let platform = platforms. first ( where: \. isCurrent) {
23
- let introspectionViewID = IntrospectionViewID ( )
24
- self . background (
25
- IntrospectionAnchorView (
26
- id: introspectionViewID
39
+ self . selector = platform. selector ?? . default
40
+ } else {
41
+ self . selector = nil
42
+ }
43
+ self . customize = customize
44
+ }
45
+
46
+ func body( content: Content ) -> some View {
47
+ if let selector {
48
+ content
49
+ . background (
50
+ IntrospectionAnchorView ( id: id)
51
+ . frame ( width: 0 , height: 0 )
27
52
)
28
- . frame ( width: 0 , height: 0 )
29
- )
30
- . overlay (
31
- IntrospectionView (
32
- id: introspectionViewID,
33
- selector: { controller in
34
- ( platform. selector ?? . default) ( controller, scope ?? viewType. scope)
35
- } ,
36
- customize: customize
53
+ . overlay (
54
+ IntrospectionView ( id: id, selector: { selector ( $0, scope) } , customize: customize)
55
+ . frame ( width: 0 , height: 0 )
37
56
)
38
- . frame ( width: 0 , height: 0 )
39
- )
40
57
} else {
41
- self
58
+ content
42
59
}
43
60
}
44
61
}
0 commit comments