Skip to content

Commit 9fb2469

Browse files
authored
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.
1 parent aef9303 commit 9fb2469

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
MeasureInWindowOnSuccessCallback,
1414
MeasureLayoutOnSuccessCallback,
1515
MeasureOnSuccessCallback,
16-
NativeMethods,
16+
INativeMethods,
1717
ViewConfig,
1818
TouchedViewDataAtPoint,
1919
} from './ReactNativeTypes';
@@ -109,7 +109,7 @@ const noop = () => {};
109109
/**
110110
* This is used for refs on host components.
111111
*/
112-
class ReactFabricHostComponent implements NativeMethods {
112+
class ReactFabricHostComponent implements INativeMethods {
113113
_nativeTag: number;
114114
viewConfig: ViewConfig;
115115
currentProps: Props;

packages/react-native-renderer/src/ReactNativeFiberHostComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
MeasureInWindowOnSuccessCallback,
1414
MeasureLayoutOnSuccessCallback,
1515
MeasureOnSuccessCallback,
16-
NativeMethods,
16+
INativeMethods,
1717
ViewConfig,
1818
} from './ReactNativeTypes';
1919
import type {Instance} from './ReactNativeHostConfig';
@@ -30,7 +30,7 @@ import {
3030
warnForStyleProps,
3131
} from './NativeMethodsMixinUtils';
3232

33-
class ReactNativeFiberHostComponent implements NativeMethods {
33+
class ReactNativeFiberHostComponent implements INativeMethods {
3434
_children: Array<Instance | number>;
3535
_nativeTag: number;
3636
_internalFiberInstanceHandleDEV: Object;

packages/react-native-renderer/src/ReactNativePublicCompat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function findHostInstance_DEPRECATED<TElementType: ElementType>(
6868
hostInstance = findHostInstance(componentOrHandle);
6969
}
7070

71+
// $FlowFixMe[incompatible-exact] we need to fix the definition of `HostComponent` to use NativeMethods as an interface, not as a type.
7172
return hostInstance;
7273
}
7374

packages/react-native-renderer/src/ReactNativeTypes.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export type PartialViewConfig = $ReadOnly<{
9595
validAttributes?: PartialAttributeConfiguration,
9696
}>;
9797

98-
export interface NativeMethods {
98+
/**
99+
* Current usages should migrate to this definition
100+
*/
101+
export interface INativeMethods {
99102
blur(): void;
100103
focus(): void;
101104
measure(callback: MeasureOnSuccessCallback): void;
@@ -108,6 +111,23 @@ export interface NativeMethods {
108111
setNativeProps(nativeProps: {...}): void;
109112
}
110113

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+
111131
export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;
112132

113133
type SecretInternalsType = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy