RN: Fix Type for ReactNative.NativeComponent (1/2)

Reviewed By: TheSavior

Differential Revision: D7984814

fbshipit-source-id: 0097819128b7f82267bceeb9d5e1b5057c5129ec
This commit is contained in:
Tim Yung
2018-05-13 00:48:49 -07:00
committed by Facebook Github Bot
parent 41a940392c
commit de11ba2a5e
3 changed files with 24 additions and 5 deletions

View File

@@ -74,4 +74,4 @@ if (__DEV__) {
ViewToExport.displayName = 'View';
}
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps, any>>);
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps>>);

View File

@@ -4,9 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
import * as React from 'react';
export type MeasureOnSuccessCallback = (
x: number,
y: number,
@@ -51,6 +54,22 @@ export type ReactNativeBaseComponentViewConfig = {
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
/**
* Class only exists for its Flow type.
*/
class ReactNativeComponent<Props> extends React.Component<Props> {
blur(): void {}
focus(): void {}
measure(callback: MeasureOnSuccessCallback): void {}
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {}
measureLayout(
relativeToNativeNode: number,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail?: () => void,
): void {}
setNativeProps(nativeProps: Object): void {}
}
/**
* This type keeps ReactNativeFiberHostComponent and NativeMethodsMixin in sync.
* It can also provide types for ReactNative applications that use NMM or refs.
@@ -86,7 +105,7 @@ type SecretInternalsFabricType = {
* Provide minimal Flow typing for the high-level RN API and call it a day.
*/
export type ReactNativeType = {
NativeComponent: any,
NativeComponent: typeof ReactNativeComponent,
findNodeHandle(componentOrHandle: any): ?number,
render(
element: React$Element<any>,
@@ -101,7 +120,7 @@ export type ReactNativeType = {
};
export type ReactFabricType = {
NativeComponent: any,
NativeComponent: typeof ReactNativeComponent,
findNodeHandle(componentOrHandle: any): ?number,
render(
element: React$Element<any>,

View File

@@ -36,7 +36,7 @@ type ResponseHandlers = $ReadOnly<{|
type Props = $ReadOnly<{
...TextProps,
forwardedRef: ?React.Ref<NativeComponent<TextProps, any>>,
forwardedRef: ?React.Ref<NativeComponent<TextProps>>,
}>;
type State = {|
@@ -270,4 +270,4 @@ Text.displayName = 'Text';
// TODO: Deprecate this.
Text.propTypes = TextPropTypes;
module.exports = ((Text: any): NativeComponent<TextProps, any>);
module.exports = ((Text: any): Class<NativeComponent<TextProps>>);