@samitouri / QOS-React-2 / commits / c29ca23af9

fix: add isChildPublicInstance to ReactNativeTypes (#27788)

Follow-up on https://github.com/facebook/react/pull/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

Ruslan Lesiutin committed Dec 5, 2023 at 13:00 UTC c29ca23af91d8aeb9e175c08a0866ba54286f0f3
2 files changed +12 -2
packages/react-native-renderer/src/ReactNativePublicCompat.js
+7 -2
@@ -8,8 +8,6 @@
8 */
9
10 import type {Node, HostComponent} from './ReactNativeTypes';
11 -import type {PublicInstance as FabricPublicInstance} from './ReactFiberConfigFabric';
12 -import type {PublicInstance as PaperPublicInstance} from './ReactFiberConfigNative';
11 import type {ElementRef, ElementType} from 'react';
12
13 // Modules provided by RN:
@@ -225,6 +223,11 @@ export function getNodeFromInternalInstanceHandle(
223 );
224 }
225
226 +// Should have been PublicInstance from ReactFiberConfigFabric
227 +type FabricPublicInstance = mixed;
228 +// Should have been PublicInstance from ReactFiberConfigNative
229 +type PaperPublicInstance = HostComponent<mixed>;
230 +
231 // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
232 export function isChildPublicInstance(
233 parentInstance: FabricPublicInstance | PaperPublicInstance,
@@ -251,8 +254,10 @@ export function isChildPublicInstance(
254 }
255
256 const parentInternalInstanceHandle =
257 + // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
258 getInternalInstanceHandleFromPublicInstance(parentInstance);
259 const childInternalInstanceHandle =
260 + // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
261 getInternalInstanceHandleFromPublicInstance(childInstance);
262
263 // Fabric
packages/react-native-renderer/src/ReactNativeTypes.js
+5
@@ -191,6 +191,10 @@ export type ReactNativeType = {
191 findNodeHandle<TElementType: ElementType>(
192 componentOrHandle: ?(ElementRef<TElementType> | number),
193 ): ?number,
194 + isChildPublicInstance(
195 + parent: PublicInstance | HostComponent<mixed>,
196 + child: PublicInstance | HostComponent<mixed>,
197 + ): boolean,
198 dispatchCommand(
199 handle: ElementRef<HostComponent<mixed>>,
200 command: string,
@@ -229,6 +233,7 @@ export type ReactFabricType = {
233 command: string,
234 args: Array<mixed>,
235 ): void,
236 + isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
237 sendAccessibilityEvent(
238 handle: ElementRef<HostComponent<mixed>>,
239 eventType: string,