Skip to content

Commit

Permalink
Fix Type for ReactNative.NativeComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
yungsters committed May 14, 2018
1 parent c802d29 commit e876fd2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
24 changes: 21 additions & 3 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +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
* @providesModule ReactNativeTypes
*/

import React from 'react';

export type MeasureOnSuccessCallback = (
x: number,
y: number,
Expand Down Expand Up @@ -52,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 @@ -87,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 @@ -102,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
1 change: 0 additions & 1 deletion packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*
* @flow
* @providesModule ReactTypes
*/

export type ReactNode =
Expand Down
4 changes: 1 addition & 3 deletions scripts/circleci/check_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
set -e

# Make sure we don't introduce accidental @providesModule annotations.
EXPECTED='packages/react-native-renderer/src/ReactNativeTypes.js
packages/shared/ReactTypes.js
scripts/rollup/wrappers.js'
EXPECTED='scripts/rollup/wrappers.js'
ACTUAL=$(git grep -l @providesModule -- './*.js' ':!scripts/rollup/shims/*.js')

# Colors
Expand Down

0 comments on commit e876fd2

Please sign in to comment.