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,12 +18,14 @@ 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
@@ -218,3 +222,44 @@ export function getNodeFromInternalInstanceHandle(
218
222
internalInstanceHandle . stateNode . node
219
223
) ;
220
224
}
225
+
226
+ // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
227
+ export function getIsOneInstanceAncestorOfAnother (
228
+ parentInstance : FabricPublicInstance | PaperPublicInstance ,
229
+ childInstance : FabricPublicInstance | PaperPublicInstance ,
230
+ ) : boolean {
231
+ if ( __DEV__ ) {
232
+ const parentInternalInstanceHandle =
233
+ getInternalInstanceHandleFromPublicInstance ( parentInstance ) ;
234
+ const childInternalInstanceHandle =
235
+ getInternalInstanceHandleFromPublicInstance ( childInstance ) ;
236
+
237
+ // Fabric
238
+ if (
239
+ parentInternalInstanceHandle != null &&
240
+ childInternalInstanceHandle != null
241
+ ) {
242
+ return doesFiberContain (
243
+ parentInternalInstanceHandle ,
244
+ childInternalInstanceHandle ,
245
+ ) ;
246
+ }
247
+
248
+ // Paper
249
+ if (
250
+ parentInstance . _internalFiberInstanceHandleDEV != null &&
251
+ childInstance . _internalFiberInstanceHandleDEV != null
252
+ ) {
253
+ return doesFiberContain (
254
+ parentInstance . _internalFiberInstanceHandleDEV ,
255
+ childInstance . _internalFiberInstanceHandleDEV ,
256
+ ) ;
257
+ }
258
+
259
+ return false ;
260
+ } else {
261
+ throw new Error (
262
+ 'getIsOneInstanceAncestorOfAnother() is not available in production.' ,
263
+ ) ;
264
+ }
265
+ }
0 commit comments