Skip to content

Commit

Permalink
fix: add isChildPublicInstance to ReactNativeTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq committed Dec 4, 2023
1 parent 223db40 commit b1e1e10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/react-native-renderer/src/ReactNativePublicCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* @flow
*/

import type {Node, HostComponent} from './ReactNativeTypes';
import type {PublicInstance as FabricPublicInstance} from './ReactFiberConfigFabric';
import type {PublicInstance as PaperPublicInstance} from './ReactFiberConfigNative';
import type {Node, HostComponent, PublicInstance} from './ReactNativeTypes';
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 = PublicInstance;
// 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] PublicInstance from ReactNativeTypes is opaque, treat it as PublicInstance from ReactFiberConfigFabric.
getInternalInstanceHandleFromPublicInstance(parentInstance);
const childInternalInstanceHandle =
// $FlowExpectedError[incompatible-call] PublicInstance from ReactNativeTypes is opaque, treat it as PublicInstance from ReactFiberConfigFabric.
getInternalInstanceHandleFromPublicInstance(childInstance);

// Fabric
Expand Down
7 changes: 6 additions & 1 deletion 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: HostComponent<mixed>,
child: HostComponent<mixed>,
): boolean,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
command: string,
Expand All @@ -214,7 +218,7 @@ export type ReactNativeType = {

export opaque type Node = mixed;
export opaque type InternalInstanceHandle = mixed;
type PublicInstance = mixed;
export opaque type PublicInstance = mixed;
type PublicTextInstance = mixed;

export type ReactFabricType = {
Expand All @@ -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 b1e1e10

Please sign in to comment.