@@ -19,128 +19,117 @@ import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
1919import invariant from 'shared/invariant' ;
2020// Module provided by RN:
2121import { UIManager } from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
22- import { enableGetInspectorDataForInstanceInProduction } from 'shared/ReactFeatureFlags' ;
2322import { getClosestInstanceFromNode } from './ReactNativeComponentTree' ;
2423
2524const emptyObject = { } ;
2625if ( __DEV__ ) {
2726 Object . freeze ( emptyObject ) ;
2827}
2928
30- let createHierarchy ;
31- let getHostNode ;
32- let getHostProps ;
33- let lastNonHostInstance ;
34- let getInspectorDataForInstance ;
35- let getOwnerHierarchy ;
36- let traverseOwnerTreeUp ;
37-
38- if ( __DEV__ || enableGetInspectorDataForInstanceInProduction ) {
39- createHierarchy = function ( fiberHierarchy ) {
40- return fiberHierarchy . map ( fiber => ( {
41- name : getComponentNameFromType ( fiber . type ) ,
42- getInspectorData : findNodeHandle => {
43- return {
44- props : getHostProps ( fiber ) ,
45- source : fiber . _debugSource ,
46- measure : callback => {
47- // If this is Fabric, we'll find a ShadowNode and use that to measure.
48- const hostFiber = findCurrentHostFiber ( fiber ) ;
49- const shadowNode =
50- hostFiber != null &&
51- hostFiber . stateNode !== null &&
52- hostFiber . stateNode . node ;
53-
54- if ( shadowNode ) {
55- nativeFabricUIManager . measure ( shadowNode , callback ) ;
56- } else {
57- return UIManager . measure (
58- getHostNode ( fiber , findNodeHandle ) ,
59- callback ,
60- ) ;
61- }
62- } ,
63- } ;
64- } ,
65- } ) ) ;
66- } ;
29+ function createHierarchy ( fiberHierarchy ) {
30+ return fiberHierarchy . map ( fiber => ( {
31+ name : getComponentNameFromType ( fiber . type ) ,
32+ getInspectorData : findNodeHandle => {
33+ return {
34+ props : getHostProps ( fiber ) ,
35+ source : fiber . _debugSource ,
36+ measure : callback => {
37+ // If this is Fabric, we'll find a ShadowNode and use that to measure.
38+ const hostFiber = findCurrentHostFiber ( fiber ) ;
39+ const shadowNode =
40+ hostFiber != null &&
41+ hostFiber . stateNode !== null &&
42+ hostFiber . stateNode . node ;
6743
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- } ;
44+ if ( shadowNode ) {
45+ nativeFabricUIManager . measure ( shadowNode , callback ) ;
46+ } else {
47+ return UIManager . measure (
48+ getHostNode ( fiber , findNodeHandle ) ,
49+ callback ,
50+ ) ;
51+ }
52+ } ,
53+ } ;
54+ } ,
55+ } ) ) ;
56+ }
8357
84- getHostProps = function ( fiber ) {
85- const host = findCurrentHostFiber ( fiber ) ;
86- if ( host ) {
87- return host . memoizedProps || emptyObject ;
58+ function getHostNode ( fiber : Fiber | null , findNodeHandle ) {
59+ let hostNode ;
60+ // look for children first for the hostNode
61+ // as composite fibers do not have a hostNode
62+ while ( fiber ) {
63+ if ( fiber . stateNode !== null && fiber . tag === HostComponent ) {
64+ hostNode = findNodeHandle ( fiber . stateNode ) ;
8865 }
89- return emptyObject ;
90- } ;
91-
92- getInspectorDataForInstance = function (
93- closestInstance : Fiber | null ,
94- ) : InspectorData {
95- // Handle case where user clicks outside of ReactNative
96- if ( ! closestInstance ) {
97- return {
98- hierarchy : [ ] ,
99- props : emptyObject ,
100- selectedIndex : null ,
101- source : null ,
102- } ;
66+ if ( hostNode ) {
67+ return hostNode ;
10368 }
69+ fiber = fiber . child ;
70+ }
71+ return null ;
72+ }
10473
105- const fiber = findCurrentFiberUsingSlowPath ( closestInstance ) ;
106- const fiberHierarchy = getOwnerHierarchy ( fiber ) ;
107- const instance = lastNonHostInstance ( fiberHierarchy ) ;
108- const hierarchy = createHierarchy ( fiberHierarchy ) ;
109- const props = getHostProps ( instance ) ;
110- const source = instance . _debugSource ;
111- const selectedIndex = fiberHierarchy . indexOf ( instance ) ;
74+ function getHostProps ( fiber ) {
75+ const host = findCurrentHostFiber ( fiber ) ;
76+ if ( host ) {
77+ return host . memoizedProps || emptyObject ;
78+ }
79+ return emptyObject ;
80+ }
11281
82+ function getInspectorDataForInstance (
83+ closestInstance : Fiber | null ,
84+ ) : InspectorData {
85+ // Handle case where user clicks outside of ReactNative
86+ if ( ! closestInstance ) {
11387 return {
114- hierarchy,
115- props,
116- selectedIndex,
117- source,
88+ hierarchy : [ ] ,
89+ props : emptyObject ,
90+ selectedIndex : null ,
91+ source : null ,
11892 } ;
119- } ;
93+ }
94+
95+ const fiber = findCurrentFiberUsingSlowPath ( closestInstance ) ;
96+ const fiberHierarchy = getOwnerHierarchy ( fiber ) ;
97+ const instance = lastNonHostInstance ( fiberHierarchy ) ;
98+ const hierarchy = createHierarchy ( fiberHierarchy ) ;
99+ const props = getHostProps ( instance ) ;
100+ const source = instance . _debugSource ;
101+ const selectedIndex = fiberHierarchy . indexOf ( instance ) ;
120102
121- getOwnerHierarchy = function ( instance : any ) {
122- const hierarchy = [ ] ;
123- traverseOwnerTreeUp ( hierarchy , instance ) ;
124- return hierarchy ;
103+ return {
104+ hierarchy,
105+ props,
106+ selectedIndex,
107+ source,
125108 } ;
109+ }
110+
111+ function getOwnerHierarchy ( instance : any ) {
112+ const hierarchy = [ ] ;
113+ traverseOwnerTreeUp ( hierarchy , instance ) ;
114+ return hierarchy ;
115+ }
126116
127- lastNonHostInstance = function ( hierarchy ) {
128- for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
129- const instance = hierarchy [ i ] ;
117+ function lastNonHostInstance ( hierarchy ) {
118+ for ( let i = hierarchy . length - 1 ; i > 1 ; i -- ) {
119+ const instance = hierarchy [ i ] ;
130120
131- if ( instance . tag !== HostComponent ) {
132- return instance ;
133- }
121+ if ( instance . tag !== HostComponent ) {
122+ return instance ;
134123 }
135- return hierarchy [ 0 ] ;
136- } ;
124+ }
125+ return hierarchy [ 0 ] ;
126+ }
137127
138- traverseOwnerTreeUp = function ( hierarchy , instance : any ) {
139- if ( instance ) {
140- hierarchy . unshift ( instance ) ;
141- traverseOwnerTreeUp ( hierarchy , instance . _debugOwner ) ;
142- }
143- } ;
128+ function traverseOwnerTreeUp ( hierarchy , instance : any ) {
129+ if ( instance ) {
130+ hierarchy . unshift ( instance ) ;
131+ traverseOwnerTreeUp ( hierarchy , instance . _debugOwner ) ;
132+ }
144133}
145134
146135let getInspectorDataForViewTag ;
0 commit comments