@@ -25,11 +25,6 @@ const Touchable = require('Touchable');
25
25
const UIManager = require ( 'UIManager' ) ;
26
26
const View = require ( 'View' ) ;
27
27
28
- if ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ) {
29
- // required for devtools to be able to edit react native styles
30
- window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . resolveRNStyle = require ( 'flattenStyle' ) ;
31
- }
32
-
33
28
class Inspector extends React . Component {
34
29
props : {
35
30
inspectedViewTag : ?number ,
@@ -67,23 +62,18 @@ class Inspector extends React.Component {
67
62
}
68
63
69
64
componentDidMount ( ) {
70
- if ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ) {
71
- ( this : any ) . attachToDevtools = this . attachToDevtools . bind ( this ) ;
72
- window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . on ( 'react-devtools' , this . attachToDevtools ) ;
73
- // if devtools is already started
74
- if ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . reactDevtoolsAgent ) {
75
- this . attachToDevtools ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . reactDevtoolsAgent ) ;
76
- }
65
+ window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . on ( 'react-devtools' , this . attachToDevtools ) ;
66
+ // if devtools is already started
67
+ if ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . reactDevtoolsAgent ) {
68
+ this . attachToDevtools ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . reactDevtoolsAgent ) ;
77
69
}
78
70
}
79
71
80
72
componentWillUnmount ( ) {
81
73
if ( this . _subs ) {
82
74
this . _subs . map ( fn => fn ( ) ) ;
83
75
}
84
- if ( window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ) {
85
- window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . off ( 'react-devtools' , this . attachToDevtools ) ;
86
- }
76
+ window . __REACT_DEVTOOLS_GLOBAL_HOOK__ . off ( 'react-devtools' , this . attachToDevtools ) ;
87
77
}
88
78
89
79
componentWillReceiveProps ( newProps : Object ) {
@@ -128,15 +118,25 @@ class Inspector extends React.Component {
128
118
129
119
setSelection ( i : number ) {
130
120
const instance = this . state . hierarchy [ i ] ;
131
- // if we inspect a stateless component we can't use the getPublicInstance method
132
- // therefore we use the internal _instance property directly.
133
- const publicInstance = instance [ '_instance' ] || { } ;
134
- const source = instance [ '_currentElement' ] && instance [ '_currentElement' ] [ '_source' ] ;
135
- UIManager . measure ( instance . getHostNode ( ) , ( x , y , width , height , left , top ) => {
121
+ const props = typeof instance . tag === 'number' ?
122
+ // Fiber
123
+ instance . memoizedProps || { } :
124
+ // Stack
125
+ ( instance [ '_instance' ] || { } ) . props || { } ;
126
+ const source = typeof instance . tag === 'number' ?
127
+ // Fiber
128
+ instance . _debugSource :
129
+ // Stack
130
+ instance [ '_currentElement' ] && instance [ '_currentElement' ] [ '_source' ] ;
131
+ const hostNode = typeof instance . tag === 'number' ?
132
+ instance . stateNode :
133
+ instance . getHostNode ( ) ;
134
+
135
+ UIManager . measure ( hostNode , ( x , y , width , height , left , top ) => {
136
136
this . setState ( {
137
137
inspected : {
138
138
frame : { left, top, width, height} ,
139
- style : publicInstance . props ? publicInstance . props . style : { } ,
139
+ style : props ? props . style : { } ,
140
140
source,
141
141
} ,
142
142
selection : i ,
@@ -155,11 +155,17 @@ class Inspector extends React.Component {
155
155
this . state . devtoolsAgent . selectFromReactInstance ( instance , true ) ;
156
156
}
157
157
158
- // if we inspect a stateless component we can't use the getPublicInstance method
159
- // therefore we use the internal _instance property directly.
160
- const publicInstance = instance [ '_instance' ] || { } ;
161
- const props = publicInstance . props || { } ;
162
- const source = instance [ '_currentElement' ] && instance [ '_currentElement' ] [ '_source' ] ;
158
+ const props = typeof instance . tag === 'number' ?
159
+ // Fiber
160
+ instance . memoizedProps || { } :
161
+ // Stack
162
+ ( instance [ '_instance' ] || { } ) . props || { } ;
163
+ const source = typeof instance . tag === 'number' ?
164
+ // Fiber
165
+ instance . _debugSource :
166
+ // Stack
167
+ instance [ '_currentElement' ] && instance [ '_currentElement' ] [ '_source' ] ;
168
+
163
169
this . setState ( {
164
170
panelPos : pointerY > Dimensions . get ( 'window' ) . height / 2 ? 'top' : 'bottom' ,
165
171
selection : hierarchy . indexOf ( instance ) ,
0 commit comments