@@ -28,6 +28,7 @@ import {
28
28
import { createPortal as createPortalImpl } from 'react-reconciler/src/ReactPortal' ;
29
29
import { setBatchingImplementation } from './legacy-events/ReactGenericBatching' ;
30
30
import ReactVersion from 'shared/ReactVersion' ;
31
+ import { getNativeTagFromPublicInstance } from './ReactFabricPublicInstanceUtils' ;
31
32
32
33
// Modules provided by RN:
33
34
import {
@@ -67,19 +68,25 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
67
68
owner . stateNode . _warnedAboutRefsInRender = true ;
68
69
}
69
70
}
71
+
70
72
if (componentOrHandle == null) {
71
73
return null ;
72
74
}
75
+
76
+ // For compatibility with Paper
73
77
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
74
- if (componentOrHandle._nativeTag) {
78
+ if (componentOrHandle._nativeTag != null ) {
75
79
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
76
80
return componentOrHandle ;
77
81
}
82
+
83
+ // Fabric-specific
78
84
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
79
- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
85
+ if (componentOrHandle.publicInstance != null ) {
80
86
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
81
- return componentOrHandle . canonical ;
87
+ return componentOrHandle . publicInstance ;
82
88
}
89
+
83
90
let hostInstance;
84
91
if (__DEV__) {
85
92
hostInstance = findHostInstanceWithWarning (
@@ -111,19 +118,28 @@ function findNodeHandle(componentOrHandle: any): ?number {
111
118
owner . stateNode . _warnedAboutRefsInRender = true ;
112
119
}
113
120
}
121
+
114
122
if (componentOrHandle == null) {
115
123
return null ;
116
124
}
125
+
117
126
if (typeof componentOrHandle === 'number') {
118
127
// Already a node handle
119
128
return componentOrHandle ;
120
129
}
130
+
131
+ // For compatibility with Paper
121
132
if (componentOrHandle._nativeTag) {
122
133
return componentOrHandle . _nativeTag ;
123
134
}
124
- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
125
- return componentOrHandle . canonical . _nativeTag ;
135
+
136
+ if (componentOrHandle.internals != null) {
137
+ const nativeTag = componentOrHandle . internals . nativeTag ;
138
+ if ( nativeTag != null ) {
139
+ return nativeTag ;
140
+ }
126
141
}
142
+
127
143
let hostInstance;
128
144
if (__DEV__) {
129
145
hostInstance = findHostInstanceWithWarning (
@@ -138,7 +154,13 @@ function findNodeHandle(componentOrHandle: any): ?number {
138
154
return hostInstance ;
139
155
}
140
156
141
- return hostInstance._nativeTag;
157
+ // For compatibility with Paper
158
+ if (hostInstance._nativeTag != null) {
159
+ return hostInstance . _nativeTag ;
160
+ }
161
+
162
+ // $FlowExpectedError[incompatible-call] this fails for the definition of `Instance` in Paper, but here it's always a Fabric instance.
163
+ return getNativeTagFromPublicInstance(hostInstance);
142
164
}
143
165
144
166
function dispatchCommand ( handle : any , command : string , args : Array < any > ) {
@@ -265,6 +287,7 @@ export {
265
287
} ;
266
288
267
289
injectIntoDevTools({
290
+ // $FlowExpectedError[incompatible-call] The type of `Instance` in `getClosestInstanceFromNode` does not match in Fabric and Paper, so it fails to typecheck here.
268
291
findFiberByHostInstance : getClosestInstanceFromNode ,
269
292
bundleType : __DEV__ ? 1 : 0 ,
270
293
version : ReactVersion ,
0 commit comments