8
8
*/
9
9
10
10
import type { Node , HostComponent } from './ReactNativeTypes' ;
11
+ import type { PublicInstance as FabricPublicInstance } from './ReactFiberConfigFabric' ;
12
+ import type { PublicInstance as PaperPublicInstance } from './ReactFiberConfigNative' ;
11
13
import type { ElementRef , ElementType } from 'react' ;
12
14
13
15
// Modules provided by RN:
@@ -16,15 +18,19 @@ import {
16
18
legacySendAccessibilityEvent ,
17
19
getNodeFromPublicInstance ,
18
20
getNativeTagFromPublicInstance ,
21
+ getInternalInstanceHandleFromPublicInstance ,
19
22
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
20
23
21
24
import {
22
25
findHostInstance ,
23
26
findHostInstanceWithWarning ,
24
27
} from 'react-reconciler/src/ReactFiberReconciler' ;
28
+ import { doesFiberContain } from 'react-reconciler/src/ReactFiberTreeReflection' ;
25
29
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
26
30
import getComponentNameFromType from 'shared/getComponentNameFromType' ;
27
31
32
+ import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent' ;
33
+
28
34
const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
29
35
30
36
export function findHostInstance_DEPRECATED < TElementType : ElementType > (
@@ -218,3 +224,50 @@ export function getNodeFromInternalInstanceHandle(
218
224
internalInstanceHandle . stateNode . node
219
225
) ;
220
226
}
227
+
228
+ // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
229
+ export function isChildPublicInstance (
230
+ parentInstance : FabricPublicInstance | PaperPublicInstance ,
231
+ childInstance : FabricPublicInstance | PaperPublicInstance ,
232
+ ) : boolean {
233
+ if ( __DEV__ ) {
234
+ // Paper
235
+ if (
236
+ parentInstance instanceof ReactNativeFiberHostComponent ||
237
+ childInstance instanceof ReactNativeFiberHostComponent
238
+ ) {
239
+ if (
240
+ parentInstance instanceof ReactNativeFiberHostComponent &&
241
+ childInstance instanceof ReactNativeFiberHostComponent
242
+ ) {
243
+ return doesFiberContain (
244
+ parentInstance . _internalFiberInstanceHandleDEV ,
245
+ childInstance . _internalFiberInstanceHandleDEV ,
246
+ ) ;
247
+ }
248
+
249
+ // Means that one instance is from Fabric and other is from Paper.
250
+ return false ;
251
+ }
252
+
253
+ const parentInternalInstanceHandle =
254
+ getInternalInstanceHandleFromPublicInstance ( parentInstance ) ;
255
+ const childInternalInstanceHandle =
256
+ getInternalInstanceHandleFromPublicInstance ( childInstance ) ;
257
+
258
+ // Fabric
259
+ if (
260
+ parentInternalInstanceHandle != null &&
261
+ childInternalInstanceHandle != null
262
+ ) {
263
+ return doesFiberContain (
264
+ parentInternalInstanceHandle ,
265
+ childInternalInstanceHandle ,
266
+ ) ;
267
+ }
268
+
269
+ return false ;
270
+ } else {
271
+ throw new Error ( 'isChildPublicInstance() is not available in production.' ) ;
272
+ }
273
+ }
0 commit comments