Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore definition of NativeMethods as an object for React Native #26341

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 21 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,23 @@ 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,
|}>;

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

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

type SecretInternalsType = {
Expand Down