Skip to content

Commit

Permalink
fix: add isChildPublicInstance to ReactNativeTypes (facebook#27788)
Browse files Browse the repository at this point in the history
Follow-up on facebook#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
  • Loading branch information
hoxyq authored and AndyPengc12 committed Apr 15, 2024
1 parent 4366af1 commit f9bc3d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react-native-renderer/src/ReactNativePublicCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/

import type {Node, HostComponent} from './ReactNativeTypes';
import type {PublicInstance as FabricPublicInstance} from './ReactFiberConfigFabric';
import type {PublicInstance as PaperPublicInstance} from './ReactFiberConfigNative';
import type {ElementRef, ElementType} from 'react';

// Modules provided by RN:
Expand Down Expand Up @@ -225,6 +223,11 @@ export function getNodeFromInternalInstanceHandle(
);
}

// Should have been PublicInstance from ReactFiberConfigFabric
type FabricPublicInstance = mixed;
// Should have been PublicInstance from ReactFiberConfigNative
type PaperPublicInstance = HostComponent<mixed>;

// Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
export function isChildPublicInstance(
parentInstance: FabricPublicInstance | PaperPublicInstance,
Expand All @@ -251,8 +254,10 @@ export function isChildPublicInstance(
}

const parentInternalInstanceHandle =
// $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
getInternalInstanceHandleFromPublicInstance(parentInstance);
const childInternalInstanceHandle =
// $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
getInternalInstanceHandleFromPublicInstance(childInstance);

// Fabric
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export type ReactNativeType = {
findNodeHandle<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?number,
isChildPublicInstance(
parent: PublicInstance | HostComponent<mixed>,
child: PublicInstance | HostComponent<mixed>,
): boolean,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
command: string,
Expand Down Expand Up @@ -229,6 +233,7 @@ export type ReactFabricType = {
command: string,
args: Array<mixed>,
): void,
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
sendAccessibilityEvent(
handle: ElementRef<HostComponent<mixed>>,
eventType: string,
Expand Down

0 comments on commit f9bc3d8

Please sign in to comment.