Skip to content

Commit de11ba2

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Fix Type for ReactNative.NativeComponent (1/2)
Reviewed By: TheSavior Differential Revision: D7984814 fbshipit-source-id: 0097819128b7f82267bceeb9d5e1b5057c5129ec
1 parent 41a9403 commit de11ba2

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Libraries/Components/View/View.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ if (__DEV__) {
7474
ViewToExport.displayName = 'View';
7575
}
7676

77-
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps, any>>);
77+
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps>>);

Libraries/Renderer/shims/ReactNativeTypes.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7+
* @format
78
* @flow
89
*/
910

11+
import * as React from 'react';
12+
1013
export type MeasureOnSuccessCallback = (
1114
x: number,
1215
y: number,
@@ -51,6 +54,22 @@ export type ReactNativeBaseComponentViewConfig = {
5154

5255
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
5356

57+
/**
58+
* Class only exists for its Flow type.
59+
*/
60+
class ReactNativeComponent<Props> extends React.Component<Props> {
61+
blur(): void {}
62+
focus(): void {}
63+
measure(callback: MeasureOnSuccessCallback): void {}
64+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {}
65+
measureLayout(
66+
relativeToNativeNode: number,
67+
onSuccess: MeasureLayoutOnSuccessCallback,
68+
onFail?: () => void,
69+
): void {}
70+
setNativeProps(nativeProps: Object): void {}
71+
}
72+
5473
/**
5574
* This type keeps ReactNativeFiberHostComponent and NativeMethodsMixin in sync.
5675
* It can also provide types for ReactNative applications that use NMM or refs.
@@ -86,7 +105,7 @@ type SecretInternalsFabricType = {
86105
* Provide minimal Flow typing for the high-level RN API and call it a day.
87106
*/
88107
export type ReactNativeType = {
89-
NativeComponent: any,
108+
NativeComponent: typeof ReactNativeComponent,
90109
findNodeHandle(componentOrHandle: any): ?number,
91110
render(
92111
element: React$Element<any>,
@@ -101,7 +120,7 @@ export type ReactNativeType = {
101120
};
102121

103122
export type ReactFabricType = {
104-
NativeComponent: any,
123+
NativeComponent: typeof ReactNativeComponent,
105124
findNodeHandle(componentOrHandle: any): ?number,
106125
render(
107126
element: React$Element<any>,

Libraries/Text/Text.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ResponseHandlers = $ReadOnly<{|
3636

3737
type Props = $ReadOnly<{
3838
...TextProps,
39-
forwardedRef: ?React.Ref<NativeComponent<TextProps, any>>,
39+
forwardedRef: ?React.Ref<NativeComponent<TextProps>>,
4040
}>;
4141

4242
type State = {|
@@ -270,4 +270,4 @@ Text.displayName = 'Text';
270270
// TODO: Deprecate this.
271271
Text.propTypes = TextPropTypes;
272272

273-
module.exports = ((Text: any): NativeComponent<TextProps, any>);
273+
module.exports = ((Text: any): Class<NativeComponent<TextProps>>);

0 commit comments

Comments
 (0)