From 622661f007286a69da98200ba75e0c4facdb2ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 8 Mar 2023 14:03:08 +0000 Subject: [PATCH] Restore definition of NativeMethods as an object for React Native --- .../src/ReactFabricHostConfig.js | 4 ++-- .../src/ReactNativeFiberHostComponent.js | 4 ++-- .../src/ReactNativePublicCompat.js | 1 + .../src/ReactNativeTypes.js | 18 +++++++++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) 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..b62ad776cf7f1 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,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>, + onSuccess: MeasureLayoutOnSuccessCallback, + onFail?: () => void, + ): void, + setNativeProps(nativeProps: {...}): void, +|}>; + export type HostComponent = AbstractComponent>; type SecretInternalsType = {