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