@@ -16,15 +16,20 @@ import {
1616 legacySendAccessibilityEvent ,
1717 getNodeFromPublicInstance ,
1818 getNativeTagFromPublicInstance ,
19+ getInternalInstanceHandleFromPublicInstance ,
1920} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' ;
2021
2122import {
2223 findHostInstance ,
2324 findHostInstanceWithWarning ,
2425} from 'react-reconciler/src/ReactFiberReconciler' ;
26+ import { doesFiberContain } from 'react-reconciler/src/ReactFiberTreeReflection' ;
2527import ReactSharedInternals from 'shared/ReactSharedInternals' ;
2628import getComponentNameFromType from 'shared/getComponentNameFromType' ;
2729
30+ import { PublicInstance as FabricPublicInstance } from './ReactFiberConfigFabric' ;
31+ import { PublicInstance as PaperPublicInstance } from './ReactFiberConfigNative' ;
32+
2833const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
2934
3035export function findHostInstance_DEPRECATED < TElementType : ElementType > (
@@ -218,3 +223,42 @@ export function getNodeFromInternalInstanceHandle(
218223 internalInstanceHandle . stateNode . node
219224 ) ;
220225}
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