@@ -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 {
@@ -44,6 +45,7 @@ import {
4445import { LegacyRoot , ConcurrentRoot } from 'react-reconciler/src/ReactRootTags' ;
4546import ReactSharedInternals from 'shared/ReactSharedInternals' ;
4647import getComponentNameFromType from 'shared/getComponentNameFromType' ;
48+ import type { PublicInstance } from './ReactFabricHostConfig' ;
4749
4850const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
4951
@@ -67,19 +69,23 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
6769 owner . stateNode . _warnedAboutRefsInRender = true ;
6870 }
6971 }
72+
7073 if (componentOrHandle == null) {
7174 return null ;
7275 }
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 ) ;
7781 }
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 ) ;
8287 }
88+
8389 let hostInstance;
8490 if (__DEV__) {
8591 hostInstance = findHostInstanceWithWarning (
@@ -111,19 +117,28 @@ function findNodeHandle(componentOrHandle: any): ?number {
111117 owner . stateNode . _warnedAboutRefsInRender = true ;
112118 }
113119 }
120+
114121 if (componentOrHandle == null) {
115122 return null ;
116123 }
124+
117125 if (typeof componentOrHandle === 'number') {
118126 // Already a node handle
119127 return componentOrHandle ;
120128 }
129+
130+ // For compatibility with Paper
121131 if (componentOrHandle._nativeTag) {
122132 return componentOrHandle . _nativeTag ;
123133 }
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+ }
126140 }
141+
127142 let hostInstance;
128143 if (__DEV__) {
129144 hostInstance = findHostInstanceWithWarning (
@@ -138,7 +153,14 @@ function findNodeHandle(componentOrHandle: any): ?number {
138153 return hostInstance ;
139154 }
140155
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);
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