Skip to content

Commit

Permalink
Define HostInstance type for React Native
Browse files Browse the repository at this point in the history
  • Loading branch information
yungsters committed Sep 30, 2024
1 parent 2d16326 commit a0cef2c
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,32 @@ export interface INativeMethods {
measure(callback: MeasureOnSuccessCallback): void;
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
measureLayout(
relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
relativeToNativeNode: number | HostInstance,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail?: () => void,
): void;
setNativeProps(nativeProps: {...}): void;
}

export type NativeMethods = $ReadOnly<{|
export type NativeMethods = $ReadOnly<{
blur(): void,
focus(): void,
measure(callback: MeasureOnSuccessCallback): void,
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
measureLayout(
relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
relativeToNativeNode: number | HostInstance,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail?: () => void,
): void,
setNativeProps(nativeProps: {...}): void,
|}>;
}>;

// This validates that INativeMethods and NativeMethods stay in sync using Flow!
declare const ensureNativeMethodsAreSynced: NativeMethods;
(ensureNativeMethodsAreSynced: INativeMethods);

export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;
export type HostInstance = NativeMethods;
export type HostComponent<Config> = AbstractComponent<Config, HostInstance>;

type SecretInternalsType = {
computeComponentStackForErrorReporting(tag: number): string,
Expand Down Expand Up @@ -209,7 +210,7 @@ export type RenderRootOptions = {
export type ReactNativeType = {
findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?ElementRef<HostComponent<mixed>>,
): ?HostInstance,
findNodeHandle<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?number,
Expand All @@ -218,14 +219,11 @@ export type ReactNativeType = {
child: PublicInstance | HostComponent<mixed>,
): boolean,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
handle: HostInstance,
command: string,
args: Array<mixed>,
): void,
sendAccessibilityEvent(
handle: ElementRef<HostComponent<mixed>>,
eventType: string,
): void,
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
render(
element: MixedElement,
containerTag: number,
Expand All @@ -247,20 +245,17 @@ type PublicTextInstance = mixed;
export type ReactFabricType = {
findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?ElementRef<HostComponent<mixed>>,
): ?HostInstance,
findNodeHandle<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?number,
dispatchCommand(
handle: ElementRef<HostComponent<mixed>>,
handle: HostInstance,
command: string,
args: Array<mixed>,
): void,
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
sendAccessibilityEvent(
handle: ElementRef<HostComponent<mixed>>,
eventType: string,
): void,
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
render(
element: MixedElement,
containerTag: number,
Expand Down

0 comments on commit a0cef2c

Please sign in to comment.