Skip to content

Commit

Permalink
Restore definition of NativeMethods as an object for React Native
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Mar 8, 2023
1 parent aef9303 commit 622661f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
INativeMethods,
ViewConfig,
TouchedViewDataAtPoint,
} from './ReactNativeTypes';
Expand Down Expand Up @@ -109,7 +109,7 @@ const noop = () => {};
/**
* This is used for refs on host components.
*/
class ReactFabricHostComponent implements NativeMethods {
class ReactFabricHostComponent implements INativeMethods {
_nativeTag: number;
viewConfig: ViewConfig;
currentProps: Props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
INativeMethods,
ViewConfig,
} from './ReactNativeTypes';
import type {Instance} from './ReactNativeHostConfig';
Expand All @@ -30,7 +30,7 @@ import {
warnForStyleProps,
} from './NativeMethodsMixinUtils';

class ReactNativeFiberHostComponent implements NativeMethods {
class ReactNativeFiberHostComponent implements INativeMethods {
_children: Array<Instance | number>;
_nativeTag: number;
_internalFiberInstanceHandleDEV: Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function findHostInstance_DEPRECATED<TElementType: ElementType>(
hostInstance = findHostInstance(componentOrHandle);
}

// $FlowFixMe[incompatible-exact] we need to fix the definition of `HostComponent` to use NativeMethods as an interface, not as a type.
return hostInstance;
}

Expand Down
18 changes: 17 additions & 1 deletion packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export type PartialViewConfig = $ReadOnly<{
validAttributes?: PartialAttributeConfiguration,
}>;

export interface NativeMethods {
/**
* Current usages should migrate to this definition
*/
export interface INativeMethods {
blur(): void;
focus(): void;
measure(callback: MeasureOnSuccessCallback): void;
Expand All @@ -108,6 +111,19 @@ export interface NativeMethods {
setNativeProps(nativeProps: {...}): void;
}

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

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

type SecretInternalsType = {
Expand Down

0 comments on commit 622661f

Please sign in to comment.