Skip to content

Commit

Permalink
RN: Fix Type for ReactNative.NativeComponent (1/2)
Browse files Browse the repository at this point in the history
Reviewed By: TheSavior

Differential Revision: D7984814

fbshipit-source-id: 0097819128b7f82267bceeb9d5e1b5057c5129ec
  • Loading branch information
yungsters authored and facebook-github-bot committed May 13, 2018
1 parent 41a9403 commit de11ba2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ if (__DEV__) {
ViewToExport.displayName = 'View';
}

module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps, any>>);
module.exports = ((ViewToExport: any): Class<NativeComponent<ViewProps>>);
23 changes: 21 additions & 2 deletions Libraries/Renderer/shims/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>,
Expand All @@ -101,7 +120,7 @@ export type ReactNativeType = {
};

export type ReactFabricType = {
NativeComponent: any,
NativeComponent: typeof ReactNativeComponent,
findNodeHandle(componentOrHandle: any): ?number,
render(
element: React$Element<any>,
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ResponseHandlers = $ReadOnly<{|

type Props = $ReadOnly<{
...TextProps,
forwardedRef: ?React.Ref<NativeComponent<TextProps, any>>,
forwardedRef: ?React.Ref<NativeComponent<TextProps>>,
}>;

type State = {|
Expand Down Expand Up @@ -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>>);

0 comments on commit de11ba2

Please sign in to comment.