@@ -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 {
@@ -44,6 +45,7 @@ import {
44
45
import { LegacyRoot , ConcurrentRoot } from 'react-reconciler/src/ReactRootTags' ;
45
46
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
46
47
import getComponentNameFromType from 'shared/getComponentNameFromType' ;
48
+ import type { PublicInstance } from './ReactFabricHostConfig' ;
47
49
48
50
const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
49
51
@@ -67,19 +69,23 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
67
69
owner . stateNode . _warnedAboutRefsInRender = true ;
68
70
}
69
71
}
72
+
70
73
if (componentOrHandle == null) {
71
74
return null ;
72
75
}
73
- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
74
- if (componentOrHandle._nativeTag) {
75
- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
76
- return componentOrHandle ;
76
+
77
+ // For compatibility with Paper
78
+ if (componentOrHandle._nativeTag != null) {
79
+ // $FlowExpectedError[incompatible-cast] For compatibility with Paper (when using Fabric)
80
+ return ( componentOrHandle : PublicInstance ) ;
77
81
}
78
- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
79
- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
80
- // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
81
- return componentOrHandle . canonical ;
82
+
83
+ // Fabric-specific
84
+ if (componentOrHandle.publicInstance != null) {
85
+ // $FlowExpectedError[incompatible-cast] For compatibility with Fabric (when using Paper)
86
+ return ( componentOrHandle . publicInstance : PublicInstance ) ;
82
87
}
88
+
83
89
let hostInstance;
84
90
if (__DEV__) {
85
91
hostInstance = findHostInstanceWithWarning (
@@ -111,19 +117,28 @@ function findNodeHandle(componentOrHandle: any): ?number {
111
117
owner . stateNode . _warnedAboutRefsInRender = true ;
112
118
}
113
119
}
120
+
114
121
if (componentOrHandle == null) {
115
122
return null ;
116
123
}
124
+
117
125
if (typeof componentOrHandle === 'number') {
118
126
// Already a node handle
119
127
return componentOrHandle ;
120
128
}
129
+
130
+ // For compatibility with Paper
121
131
if (componentOrHandle._nativeTag) {
122
132
return componentOrHandle . _nativeTag ;
123
133
}
124
- if (componentOrHandle.canonical && componentOrHandle . canonical . _nativeTag ) {
125
- return componentOrHandle . canonical . _nativeTag ;
134
+
135
+ if (componentOrHandle.internals != null) {
136
+ const nativeTag = componentOrHandle . internals . nativeTag ;
137
+ if ( nativeTag != null ) {
138
+ return nativeTag ;
139
+ }
126
140
}
141
+
127
142
let hostInstance;
128
143
if (__DEV__) {
129
144
hostInstance = findHostInstanceWithWarning (
@@ -138,7 +153,14 @@ function findNodeHandle(componentOrHandle: any): ?number {
138
153
return hostInstance ;
139
154
}
140
155
141
- return hostInstance._nativeTag;
156
+ // $FlowExpectedError[prop-missing] For compatibility with Paper (when using Fabric)
157
+ if (hostInstance._nativeTag != null) {
158
+ // $FlowExpectedError[incompatible-return]
159
+ return hostInstance . _nativeTag ;
160
+ }
161
+
162
+ // $FlowExpectedError[incompatible-call] For compatibility with Fabric (when using Paper)
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