Enable flow in react-native-implementation

Summary:
I noticed I didn't get type defs anymore for react-native. Looks like it is broken since we removed the .flow file in 3e153b2a5b. To fix it we can now enable flow in react-native-implementation since it now supports properties.

**Test plan**
Tested that I get type hints when using imports from react-native in a project.
Closes https://github.com/facebook/react-native/pull/12917

Differential Revision: D4704753

Pulled By: ericvicenti

fbshipit-source-id: cf882588d7f371931de8d7861a1a6d50f6c425dc
This commit is contained in:
Janic Duplessis
2017-04-05 10:16:30 -07:00
committed by Facebook Github Bot
parent 9a51fa8e15
commit c7387fefc8
8 changed files with 53 additions and 60 deletions

View File

@@ -198,7 +198,7 @@ class FlatListExample extends React.PureComponent {
this._listRef.getNode().recordInteraction(); this._listRef.getNode().recordInteraction();
pressItem(this, key); pressItem(this, key);
}; };
_listRef: FlatList<*>; _listRef: AnimatedFlatList;
} }

View File

@@ -49,7 +49,7 @@ class Tester extends React.Component {
this.current && this.props.reverseConfig ? this.props.reverseConfig : this.props.config this.current && this.props.reverseConfig ? this.props.reverseConfig : this.props.config
); );
this.current = this.current ? 0 : 1; this.current = this.current ? 0 : 1;
const config = { const config: Object = {
...animConfig, ...animConfig,
toValue: this.current, toValue: this.current,
}; };

View File

@@ -71,7 +71,7 @@ exports.examples = [
description: 'You can display <ScrollView>\'s child components horizontally rather than vertically', description: 'You can display <ScrollView>\'s child components horizontally rather than vertically',
render: function() { render: function() {
function renderScrollView(title: string, addtionalStyles: StyleSheet) { function renderScrollView(title: string, addtionalStyles: typeof StyleSheet) {
var _scrollView: ScrollView; var _scrollView: ScrollView;
return ( return (
<View style={addtionalStyles}> <View style={addtionalStyles}>

View File

@@ -33,6 +33,44 @@ var pickerStyleType = StyleSheetPropType({
var MODE_DIALOG = 'dialog'; var MODE_DIALOG = 'dialog';
var MODE_DROPDOWN = 'dropdown'; var MODE_DROPDOWN = 'dropdown';
/**
* Individual selectable item in a Picker.
*/
class PickerItem extends React.Component {
props: {
label: string,
value?: any,
color?: ColorPropType,
testID?: string,
};
static propTypes = {
/**
* Text to display for this item.
*/
label: React.PropTypes.string.isRequired,
/**
* The value to be passed to picker's `onValueChange` callback when
* this item is selected. Can be a string or an integer.
*/
value: React.PropTypes.any,
/**
* Color of this item's text.
* @platform android
*/
color: ColorPropType,
/**
* Used to locate the item in end-to-end tests.
*/
testID: React.PropTypes.string,
};
render() {
// The items are not rendered directly
throw null;
}
}
/** /**
* Renders the native picker component on iOS and Android. Example: * Renders the native picker component on iOS and Android. Example:
* *
@@ -65,6 +103,8 @@ class Picker extends React.Component {
*/ */
static MODE_DROPDOWN = MODE_DROPDOWN; static MODE_DROPDOWN = MODE_DROPDOWN;
static Item = PickerItem;
static defaultProps = { static defaultProps = {
mode: MODE_DIALOG, mode: MODE_DIALOG,
}; };
@@ -127,43 +167,4 @@ class Picker extends React.Component {
} }
} }
/**
* Individual selectable item in a Picker.
*/
// $FlowFixMe found when converting React.createClass to ES6
Picker.Item = class extends React.Component {
props: {
label: string,
value?: any,
color?: ColorPropType,
testID?: string,
};
static propTypes = {
/**
* Text to display for this item.
*/
label: React.PropTypes.string.isRequired,
/**
* The value to be passed to picker's `onValueChange` callback when
* this item is selected. Can be a string or an integer.
*/
value: React.PropTypes.any,
/**
* Color of this item's text.
* @platform android
*/
color: ColorPropType,
/**
* Used to locate the item in end-to-end tests.
*/
testID: React.PropTypes.string,
};
render() {
// The items are not rendered directly
throw null;
}
};
module.exports = Picker; module.exports = Picker;

View File

@@ -18,6 +18,11 @@ const SwipeableRow = require('SwipeableRow');
const {PropTypes} = React; const {PropTypes} = React;
type DefaultProps = {
bounceFirstRowOnMount: boolean,
renderQuickActions: Function,
};
type Props = { type Props = {
bounceFirstRowOnMount: boolean, bounceFirstRowOnMount: boolean,
dataSource: SwipeableListViewDataSource, dataSource: SwipeableListViewDataSource,
@@ -49,7 +54,7 @@ type State = {
* - It can bounce the 1st row of the list so users know it's swipeable * - It can bounce the 1st row of the list so users know it's swipeable
* - More to come * - More to come
*/ */
class SwipeableListView extends React.Component { class SwipeableListView extends React.Component<DefaultProps, Props, State> {
props: Props; props: Props;
state: State; state: State;

View File

@@ -194,7 +194,7 @@ var Image = React.createClass({
getSize( getSize(
url: string, url: string,
success: (width: number, height: number) => void, success: (width: number, height: number) => void,
failure: (error: any) => void, failure?: (error: any) => void,
) { ) {
return ImageLoader.getSize(url) return ImageLoader.getSize(url)
.then(function(sizes) { .then(function(sizes) {

View File

@@ -304,7 +304,7 @@ const Image = React.createClass({
getSize: function( getSize: function(
uri: string, uri: string,
success: (width: number, height: number) => void, success: (width: number, height: number) => void,
failure: (error: any) => void, failure?: (error: any) => void,
) { ) {
ImageViewManager.getSize(uri, success, failure || function() { ImageViewManager.getSize(uri, success, failure || function() {
console.warn('Failed to get size for image: ' + uri); console.warn('Failed to get size for image: ' + uri);

View File

@@ -7,24 +7,11 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule react-native-implementation * @providesModule react-native-implementation
* @noflow - get/set properties not yet supported by flow. also `...require(x)` is broken #6560135 * @flow
*/ */
'use strict'; 'use strict';
const invariant = require('fbjs/lib/invariant'); const invariant = require('fbjs/lib/invariant');
const warning = require('fbjs/lib/warning');
if (__DEV__) {
var warningDedupe = {};
var addonWarn = function(prevName, newPackageName) {
warning(
warningDedupe[prevName],
'React.addons.' + prevName + ' is deprecated. Please import the "' +
newPackageName + '" package instead.'
);
warningDedupe[prevName] = true;
};
}
// Export React, plus some native additions. // Export React, plus some native additions.
const ReactNative = { const ReactNative = {
@@ -118,6 +105,7 @@ const ReactNative = {
get Platform() { return require('Platform'); }, get Platform() { return require('Platform'); },
get processColor() { return require('processColor'); }, get processColor() { return require('processColor'); },
get requireNativeComponent() { return require('requireNativeComponent'); }, get requireNativeComponent() { return require('requireNativeComponent'); },
get takeSnapshot() { return require('takeSnapshot'); },
// Prop Types // Prop Types
get ColorPropType() { return require('ColorPropType'); }, get ColorPropType() { return require('ColorPropType'); },
@@ -133,7 +121,6 @@ const ReactNative = {
'and imported from `react-native-deprecated-custom-components` instead of `react-native`. ' + 'and imported from `react-native-deprecated-custom-components` instead of `react-native`. ' +
'Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html' 'Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html'
); );
return null;
}, },
}; };