@@ -21,47 +21,47 @@ import {
2121 UIManager ,
2222 getNodeFromPublicInstance ,
2323} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
24- import { enableGetInspectorDataForInstanceInProduction } from 'shared/ReactFeatureFlags' ;
2524import { getClosestInstanceFromNode } from './ReactNativeComponentTree' ;
2625import {
2726 getNodeFromInternalInstanceHandle ,
2827 findNodeHandle ,
2928} from './ReactNativePublicCompat' ;
3029import { getStackByFiberInDevAndProd } from 'react-reconciler/src/ReactFiberComponentStack' ;
3130
32- const emptyObject = { } ;
31+ let getInspectorDataForInstance : (
32+ closestInstance : Fiber | null ,
33+ ) => InspectorData ;
34+
3335if ( __DEV__ ) {
34- Object . freeze ( emptyObject ) ;
35- }
36+ const emptyObject = Object . freeze ( { } ) ;
3637
37- // $FlowFixMe[missing-local-annot]
38- function createHierarchy ( fiberHierarchy ) {
39- return fiberHierarchy . map ( fiber => ( {
40- name : getComponentNameFromType ( fiber . type ) ,
41- getInspectorData : ( ) => {
42- return {
43- props : getHostProps ( fiber ) ,
44- measure : callback => {
45- // If this is Fabric, we'll find a shadow node and use that to measure.
46- const hostFiber = findCurrentHostFiber ( fiber ) ;
47- const node =
48- hostFiber != null &&
49- hostFiber . stateNode !== null &&
50- hostFiber . stateNode . node ;
38+ // $FlowFixMe[missing-local-annot]
39+ const createHierarchy = function ( fiberHierarchy ) {
40+ return fiberHierarchy . map ( fiber => ( {
41+ name : getComponentNameFromType ( fiber . type ) ,
42+ getInspectorData : ( ) => {
43+ return {
44+ props : getHostProps ( fiber ) ,
45+ measure : callback => {
46+ // If this is Fabric, we'll find a shadow node and use that to measure.
47+ const hostFiber = findCurrentHostFiber ( fiber ) ;
48+ const node =
49+ hostFiber != null &&
50+ hostFiber . stateNode !== null &&
51+ hostFiber . stateNode . node ;
5152
52- if ( node ) {
53- nativeFabricUIManager . measure ( node , callback ) ;
54- } else {
55- return UIManager . measure ( getHostNode ( fiber ) , callback ) ;
56- }
57- } ,
58- } ;
59- } ,
60- } ) ) ;
61- }
53+ if ( node ) {
54+ nativeFabricUIManager . measure ( node , callback ) ;
55+ } else {
56+ return UIManager . measure ( getHostNode ( fiber ) , callback ) ;
57+ }
58+ } ,
59+ } ;
60+ } ,
61+ } ) ) ;
62+ } ;
6263
63- function getHostNode ( fiber : Fiber | null ) {
64- if ( __DEV__ || enableGetInspectorDataForInstanceInProduction ) {
64+ const getHostNode = function ( fiber : Fiber | null ) {
6565 let hostNode ;
6666 // look for children first for the hostNode
6767 // as composite fibers do not have a hostNode
@@ -75,22 +75,19 @@ function getHostNode(fiber: Fiber | null) {
7575 fiber = fiber . child ;
7676 }
7777 return null ;
78- }
79- }
78+ } ;
8079
81- // $FlowFixMe[missing-local-annot]
82- function getHostProps ( fiber ) {
83- const host = findCurrentHostFiber ( fiber ) ;
84- if ( host ) {
85- return host . memoizedProps || emptyObject ;
86- }
87- return emptyObject ;
88- }
80+ const getHostProps = function ( fiber : Fiber ) {
81+ const host = findCurrentHostFiber ( fiber ) ;
82+ if ( host ) {
83+ return host . memoizedProps || emptyObject ;
84+ }
85+ return emptyObject ;
86+ } ;
8987
90- function getInspectorDataForInstance (
91- closestInstance : Fiber | null ,
92- ) : InspectorData {
93- if ( __DEV__ || enableGetInspectorDataForInstanceInProduction ) {
88+ getInspectorDataForInstance = function (
89+ closestInstance : Fiber | null ,
90+ ) : InspectorData {
9491 // Handle case where user clicks outside of ReactNative
9592 if ( ! closestInstance ) {
9693 return {
@@ -125,50 +122,43 @@ function getInspectorDataForInstance(
125122 selectedIndex,
126123 componentStack,
127124 } ;
128- }
125+ } ;
129126
130- throw new Error (
131- 'getInspectorDataForInstance() is not available in production' ,
132- ) ;
133- }
134-
135- function getOwnerHierarchy ( instance : Fiber ) {
136- const hierarchy : Array < $FlowFixMe > = [];
137- traverseOwnerTreeUp(hierarchy, instance);
138- return hierarchy;
139- }
127+ const getOwnerHierarchy = function ( instance : Fiber ) {
128+ const hierarchy : Array < $FlowFixMe > = [];
129+ traverseOwnerTreeUp(hierarchy, instance);
130+ return hierarchy;
131+ } ;
140132
141- // $FlowFixMe[missing-local-annot]
142- function lastNonHostInstance ( hierarchy ) {
143- for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
144- const instance = hierarchy [ i ] ;
133+ // $FlowFixMe[missing-local-annot]
134+ const lastNonHostInstance = function ( hierarchy ) {
135+ for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
136+ const instance = hierarchy [ i ] ;
145137
146- if ( instance . tag !== HostComponent ) {
147- return instance ;
138+ if ( instance . tag !== HostComponent ) {
139+ return instance ;
140+ }
148141 }
149- }
150- return hierarchy [ 0 ] ;
151- }
142+ return hierarchy [ 0 ] ;
143+ } ;
152144
153- function traverseOwnerTreeUp (
154- hierarchy : Array < $FlowFixMe > ,
155- instance : Fiber ,
156- ) : void {
157- if ( __DEV__ || enableGetInspectorDataForInstanceInProduction ) {
145+ const traverseOwnerTreeUp = function (
146+ hierarchy : Array < $FlowFixMe > ,
147+ instance : Fiber ,
148+ ) : void {
158149 hierarchy . unshift ( instance ) ;
159150 const owner = instance . _debugOwner ;
160151 if ( owner != null && typeof owner . tag === 'number' ) {
161152 traverseOwnerTreeUp ( hierarchy , ( owner : any ) ) ;
162153 } else {
163154 // TODO: Traverse Server Components owners.
164155 }
165- }
156+ } ;
166157}
167158
168159function getInspectorDataForViewTag ( viewTag : number ) : InspectorData {
169160 if ( __DEV__ ) {
170161 const closestInstance = getClosestInstanceFromNode ( viewTag ) ;
171-
172162 return getInspectorDataForInstance ( closestInstance ) ;
173163 } else {
174164 throw new Error (
0 commit comments