@samitouri / QOS-React-2 / commits / 9fb2469a63

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.

Rubén Norte committed Mar 8, 2023 at 14:37 UTC 9fb2469a63d32f2ff9788b70ee8e9b6dc4442c06
4 files changed +26 -5
packages/react-native-renderer/src/ReactFabricHostConfig.js
+2 -2
@@ -13,7 +13,7 @@ import type {
13 MeasureInWindowOnSuccessCallback,
14 MeasureLayoutOnSuccessCallback,
15 MeasureOnSuccessCallback,
16 - NativeMethods,
16 + INativeMethods,
17 ViewConfig,
18 TouchedViewDataAtPoint,
19 } from './ReactNativeTypes';
@@ -109,7 +109,7 @@ const noop = () => {};
109 /**
110 * This is used for refs on host components.
111 */
112 -class ReactFabricHostComponent implements NativeMethods {
112 +class ReactFabricHostComponent implements INativeMethods {
113 _nativeTag: number;
114 viewConfig: ViewConfig;
115 currentProps: Props;
packages/react-native-renderer/src/ReactNativeFiberHostComponent.js
+2 -2
@@ -13,7 +13,7 @@ import type {
13 MeasureInWindowOnSuccessCallback,
14 MeasureLayoutOnSuccessCallback,
15 MeasureOnSuccessCallback,
16 - NativeMethods,
16 + INativeMethods,
17 ViewConfig,
18 } from './ReactNativeTypes';
19 import type {Instance} from './ReactNativeHostConfig';
@@ -30,7 +30,7 @@ import {
30 warnForStyleProps,
31 } from './NativeMethodsMixinUtils';
32
33 -class ReactNativeFiberHostComponent implements NativeMethods {
33 +class ReactNativeFiberHostComponent implements INativeMethods {
34 _children: Array<Instance | number>;
35 _nativeTag: number;
36 _internalFiberInstanceHandleDEV: Object;
packages/react-native-renderer/src/ReactNativePublicCompat.js
+1
@@ -68,6 +68,7 @@ export function findHostInstance_DEPRECATED<TElementType: ElementType>(
68 hostInstance = findHostInstance(componentOrHandle);
69 }
70
71 + // $FlowFixMe[incompatible-exact] we need to fix the definition of `HostComponent` to use NativeMethods as an interface, not as a type.
72 return hostInstance;
73 }
74
packages/react-native-renderer/src/ReactNativeTypes.js
+21 -1
@@ -95,7 +95,10 @@ export type PartialViewConfig = $ReadOnly<{
95 validAttributes?: PartialAttributeConfiguration,
96 }>;
97
98 -export interface NativeMethods {
98 +/**
99 + * Current usages should migrate to this definition
100 + */
101 +export interface INativeMethods {
102 blur(): void;
103 focus(): void;
104 measure(callback: MeasureOnSuccessCallback): void;
@@ -108,6 +111,23 @@ export interface NativeMethods {
111 setNativeProps(nativeProps: {...}): void;
112 }
113
114 +export type NativeMethods = $ReadOnly<{|
115 + blur(): void,
116 + focus(): void,
117 + measure(callback: MeasureOnSuccessCallback): void,
118 + measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
119 + measureLayout(
120 + relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
121 + onSuccess: MeasureLayoutOnSuccessCallback,
122 + onFail?: () => void,
123 + ): void,
124 + setNativeProps(nativeProps: {...}): void,
125 +|}>;
126 +
127 +// This validates that INativeMethods and NativeMethods stay in sync using Flow!
128 +declare var ensureNativeMethodsAreSynced: NativeMethods;
129 +(ensureNativeMethodsAreSynced: INativeMethods);
130 +
131 export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;
132
133 type SecretInternalsType = {