diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 09cb55a572fcd..717a496453eda 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -13,7 +13,7 @@ import type { MeasureInWindowOnSuccessCallback, MeasureLayoutOnSuccessCallback, MeasureOnSuccessCallback, - NativeMethods, + INativeMethods, ViewConfig, TouchedViewDataAtPoint, } from './ReactNativeTypes'; @@ -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; diff --git a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js index daf9f6774751a..3db5948c4eb0d 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +++ b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js @@ -13,7 +13,7 @@ import type { MeasureInWindowOnSuccessCallback, MeasureLayoutOnSuccessCallback, MeasureOnSuccessCallback, - NativeMethods, + INativeMethods, ViewConfig, } from './ReactNativeTypes'; import type {Instance} from './ReactNativeHostConfig'; @@ -30,7 +30,7 @@ import { warnForStyleProps, } from './NativeMethodsMixinUtils'; -class ReactNativeFiberHostComponent implements NativeMethods { +class ReactNativeFiberHostComponent implements INativeMethods { _children: Array; _nativeTag: number; _internalFiberInstanceHandleDEV: Object; diff --git a/packages/react-native-renderer/src/ReactNativePublicCompat.js b/packages/react-native-renderer/src/ReactNativePublicCompat.js index 50fbf21d0abb1..a6be670d912cb 100644 --- a/packages/react-native-renderer/src/ReactNativePublicCompat.js +++ b/packages/react-native-renderer/src/ReactNativePublicCompat.js @@ -68,6 +68,7 @@ export function findHostInstance_DEPRECATED( 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; } diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index db69a469c5123..a524d4313866c 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -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; @@ -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>, + 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 = AbstractComponent>; type SecretInternalsType = {