@@ -19,67 +19,24 @@ import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
19
19
import invariant from 'shared/invariant' ;
20
20
// Module provided by RN:
21
21
import { UIManager } from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
22
-
22
+ import { enableGetInspectorDataForInstanceInProduction } from 'shared/ReactFeatureFlags' ;
23
23
import { getClosestInstanceFromNode } from './ReactNativeComponentTree' ;
24
24
25
25
const emptyObject = { } ;
26
26
if ( __DEV__ ) {
27
27
Object . freeze ( emptyObject ) ;
28
28
}
29
29
30
- let getInspectorDataForViewTag ;
31
- let getInspectorDataForViewAtPoint ;
32
-
33
- if ( __DEV__ ) {
34
- const traverseOwnerTreeUp = function ( hierarchy , instance : any ) {
35
- if ( instance ) {
36
- hierarchy . unshift ( instance ) ;
37
- traverseOwnerTreeUp ( hierarchy , instance . _debugOwner ) ;
38
- }
39
- } ;
40
-
41
- const getOwnerHierarchy = function ( instance : any ) {
42
- const hierarchy = [ ] ;
43
- traverseOwnerTreeUp ( hierarchy , instance ) ;
44
- return hierarchy ;
45
- } ;
46
-
47
- const lastNonHostInstance = function ( hierarchy ) {
48
- for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
49
- const instance = hierarchy [ i ] ;
50
-
51
- if ( instance . tag !== HostComponent ) {
52
- return instance ;
53
- }
54
- }
55
- return hierarchy [ 0 ] ;
56
- } ;
57
-
58
- const getHostProps = function ( fiber ) {
59
- const host = findCurrentHostFiber ( fiber ) ;
60
- if ( host ) {
61
- return host . memoizedProps || emptyObject ;
62
- }
63
- return emptyObject ;
64
- } ;
65
-
66
- const getHostNode = function ( fiber : Fiber | null , findNodeHandle ) {
67
- let hostNode ;
68
- // look for children first for the hostNode
69
- // as composite fibers do not have a hostNode
70
- while ( fiber ) {
71
- if ( fiber . stateNode !== null && fiber . tag === HostComponent ) {
72
- hostNode = findNodeHandle ( fiber . stateNode ) ;
73
- }
74
- if ( hostNode ) {
75
- return hostNode ;
76
- }
77
- fiber = fiber . child ;
78
- }
79
- return null ;
80
- } ;
30
+ let createHierarchy ;
31
+ let getHostNode ;
32
+ let getHostProps ;
33
+ let lastNonHostInstance ;
34
+ let getInspectorDataForInstance ;
35
+ let getOwnerHierarchy ;
36
+ let traverseOwnerTreeUp ;
81
37
82
- const createHierarchy = function ( fiberHierarchy ) {
38
+ if ( __DEV__ || enableGetInspectorDataForInstanceInProduction ) {
39
+ createHierarchy = function ( fiberHierarchy ) {
83
40
return fiberHierarchy . map ( fiber => ( {
84
41
name : getComponentNameFromType ( fiber . type ) ,
85
42
getInspectorData : findNodeHandle => {
@@ -108,7 +65,33 @@ if (__DEV__) {
108
65
} ) ) ;
109
66
} ;
110
67
111
- const getInspectorDataForInstance = function ( closestInstance ) : InspectorData {
68
+ getHostNode = function ( fiber : Fiber | null , findNodeHandle ) {
69
+ let hostNode ;
70
+ // look for children first for the hostNode
71
+ // as composite fibers do not have a hostNode
72
+ while ( fiber ) {
73
+ if ( fiber . stateNode !== null && fiber . tag === HostComponent ) {
74
+ hostNode = findNodeHandle ( fiber . stateNode ) ;
75
+ }
76
+ if ( hostNode ) {
77
+ return hostNode ;
78
+ }
79
+ fiber = fiber . child ;
80
+ }
81
+ return null ;
82
+ } ;
83
+
84
+ getHostProps = function ( fiber ) {
85
+ const host = findCurrentHostFiber ( fiber ) ;
86
+ if ( host ) {
87
+ return host . memoizedProps || emptyObject ;
88
+ }
89
+ return emptyObject ;
90
+ } ;
91
+
92
+ getInspectorDataForInstance = function (
93
+ closestInstance : Fiber | null ,
94
+ ) : InspectorData {
112
95
// Handle case where user clicks outside of ReactNative
113
96
if ( ! closestInstance ) {
114
97
return {
@@ -135,6 +118,35 @@ if (__DEV__) {
135
118
} ;
136
119
} ;
137
120
121
+ getOwnerHierarchy = function ( instance : any ) {
122
+ const hierarchy = [ ] ;
123
+ traverseOwnerTreeUp ( hierarchy , instance ) ;
124
+ return hierarchy ;
125
+ } ;
126
+
127
+ lastNonHostInstance = function ( hierarchy ) {
128
+ for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
129
+ const instance = hierarchy [ i ] ;
130
+
131
+ if ( instance . tag !== HostComponent ) {
132
+ return instance ;
133
+ }
134
+ }
135
+ return hierarchy [ 0 ] ;
136
+ } ;
137
+
138
+ traverseOwnerTreeUp = function ( hierarchy , instance : any ) {
139
+ if ( instance ) {
140
+ hierarchy . unshift ( instance ) ;
141
+ traverseOwnerTreeUp ( hierarchy , instance . _debugOwner ) ;
142
+ }
143
+ } ;
144
+ }
145
+
146
+ let getInspectorDataForViewTag ;
147
+ let getInspectorDataForViewAtPoint ;
148
+
149
+ if ( __DEV__ ) {
138
150
getInspectorDataForViewTag = function ( viewTag : number ) : Object {
139
151
const closestInstance = getClosestInstanceFromNode ( viewTag ) ;
140
152
@@ -258,4 +270,8 @@ if (__DEV__) {
258
270
} ;
259
271
}
260
272
261
- export { getInspectorDataForViewAtPoint , getInspectorDataForViewTag } ;
273
+ export {
274
+ getInspectorDataForInstance ,
275
+ getInspectorDataForViewAtPoint ,
276
+ getInspectorDataForViewTag ,
277
+ } ;
0 commit comments