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

## Summary

In #26283, I changed definition of `NativeMethods` from an object to an
interface. This is correct but introduces a lot of errors in React
Native, so this restores the original definition and exports the fixed
type as a separate type so we can gradually migrate in React Native.

## How did you test this change?

Manually applied this change in React Native and validated the errors
are gone.
This commit is contained in:
Rubén Norte
2023-03-08 14:37:37 +00:00
committed by GitHub
parent aef930314f
commit 9fb2469a63
4 changed files with 26 additions and 5 deletions
@@ -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;
@@ -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<Instance | number>;
_nativeTag: number;
_internalFiberInstanceHandleDEV: Object;
@@ -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;
}
+21 -1
View File
@@ -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<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 = {