Skip to content

Commit c29ca23

Browse files
authored
fix: add isChildPublicInstance to ReactNativeTypes (#27788)
Follow-up on #27783. React Native is actually using `ReactNativeTypes`, which are synced from this repo. In order to make `isChildPublicInstance` visible for renderers inside React Native repository, we need to list it in `ReactNativeTypes`. Because of current circular dependency between React Native and React, it is impossible to actually type it properly: - Can't import any types in `ReactNativeTypes` from local files, because it will break React Native, once synced. - Implementations can't use real types in their definitions, because it will break these checks: https://github.com/facebook/react/blob/223db40d5a04dc3311f963f5296675f7f43139e8/packages/react-native-renderer/fabric.js#L12-L13 https://github.com/facebook/react/blob/223db40d5a04dc3311f963f5296675f7f43139e8/packages/react-native-renderer/index.js#L12-L14
1 parent 5ab6bbb commit c29ca23

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/react-native-renderer/src/ReactNativePublicCompat.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*/
99

1010
import type {Node, HostComponent} from './ReactNativeTypes';
11-
import type {PublicInstance as FabricPublicInstance} from './ReactFiberConfigFabric';
12-
import type {PublicInstance as PaperPublicInstance} from './ReactFiberConfigNative';
1311
import type {ElementRef, ElementType} from 'react';
1412

1513
// Modules provided by RN:
@@ -225,6 +223,11 @@ export function getNodeFromInternalInstanceHandle(
225223
);
226224
}
227225

226+
// Should have been PublicInstance from ReactFiberConfigFabric
227+
type FabricPublicInstance = mixed;
228+
// Should have been PublicInstance from ReactFiberConfigNative
229+
type PaperPublicInstance = HostComponent<mixed>;
230+
228231
// Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
229232
export function isChildPublicInstance(
230233
parentInstance: FabricPublicInstance | PaperPublicInstance,
@@ -251,8 +254,10 @@ export function isChildPublicInstance(
251254
}
252255

253256
const parentInternalInstanceHandle =
257+
// $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
254258
getInternalInstanceHandleFromPublicInstance(parentInstance);
255259
const childInternalInstanceHandle =
260+
// $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
256261
getInternalInstanceHandleFromPublicInstance(childInstance);
257262

258263
// Fabric

packages/react-native-renderer/src/ReactNativeTypes.js

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export type ReactNativeType = {
191191
findNodeHandle<TElementType: ElementType>(
192192
componentOrHandle: ?(ElementRef<TElementType> | number),
193193
): ?number,
194+
isChildPublicInstance(
195+
parent: PublicInstance | HostComponent<mixed>,
196+
child: PublicInstance | HostComponent<mixed>,
197+
): boolean,
194198
dispatchCommand(
195199
handle: ElementRef<HostComponent<mixed>>,
196200
command: string,
@@ -229,6 +233,7 @@ export type ReactFabricType = {
229233
command: string,
230234
args: Array<mixed>,
231235
): void,
236+
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
232237
sendAccessibilityEvent(
233238
handle: ElementRef<HostComponent<mixed>>,
234239
eventType: string,

0 commit comments

Comments
 (0)