@@ -28,6 +28,7 @@ import {
2828import { createPortal as createPortalImpl } from 'react-reconciler/src/ReactPortal' ;
2929import { setBatchingImplementation } from './legacy-events/ReactGenericBatching' ;
3030import ReactVersion from 'shared/ReactVersion' ;
31+ import { getNativeTagFromPublicInstance } from './ReactFabricPublicInstanceUtils' ;
3132
3233// Modules provided by RN:
3334import {
@@ -67,19 +68,25 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
6768 owner . stateNode . _warnedAboutRefsInRender = true ;
6869 }
6970 }
71+
7072 if (componentOrHandle == null) {
7173 return null ;
7274 }
75+
76+ // For compatibility with Paper
7377 // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
74- if (componentOrHandle._nativeTag) {
78+ if (componentOrHandle._nativeTag != null ) {
7579 // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
7680 return componentOrHandle ;
7781 }
82+
83+ // Fabric-specific
7884 // $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 ) {
8086 // $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN
81- return componentOrHandle . canonical ;
87+ return componentOrHandle . publicInstance ;
8288 }
89+
8390 let hostInstance;
8491 if (__DEV__) {
8592 hostInstance = findHostInstanceWithWarning (
@@ -111,19 +118,28 @@ function findNodeHandle(componentOrHandle: any): ?number {
111118 owner . stateNode . _warnedAboutRefsInRender = true ;
112119 }
113120 }
121+
114122 if (componentOrHandle == null) {
115123 return null ;
116124 }
125+
117126 if (typeof componentOrHandle === 'number') {
118127 // Already a node handle
119128 return componentOrHandle ;
120129 }
130+
131+ // For compatibility with Paper
121132 if (componentOrHandle._nativeTag) {
122133 return componentOrHandle . _nativeTag ;
123134 }
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+ }
126141 }
142+
127143 let hostInstance;
128144 if (__DEV__) {
129145 hostInstance = findHostInstanceWithWarning (
@@ -138,7 +154,13 @@ function findNodeHandle(componentOrHandle: any): ?number {
138154 return hostInstance ;
139155 }
140156
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);
142164}
143165
144166function dispatchCommand ( handle : any , command : string , args : Array < any > ) {
@@ -265,6 +287,7 @@ export {
265287} ;
266288
267289injectIntoDevTools({
290+ // $FlowExpectedError[incompatible-call] The type of `Instance` in `getClosestInstanceFromNode` does not match in Fabric and Paper, so it fails to typecheck here.
268291 findFiberByHostInstance : getClosestInstanceFromNode ,
269292 bundleType : __DEV__ ? 1 : 0 ,
270293 version : ReactVersion ,
0 commit comments