Skip to content

Commit c7387fe

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
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 3e153b2. 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 #12917 Differential Revision: D4704753 Pulled By: ericvicenti fbshipit-source-id: cf882588d7f371931de8d7861a1a6d50f6c425dc
1 parent 9a51fa8 commit c7387fe

File tree

8 files changed

+53
-60
lines changed

8 files changed

+53
-60
lines changed

Examples/UIExplorer/js/FlatListExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class FlatListExample extends React.PureComponent {
198198
this._listRef.getNode().recordInteraction();
199199
pressItem(this, key);
200200
};
201-
_listRef: FlatList<*>;
201+
_listRef: AnimatedFlatList;
202202
}
203203

204204

Examples/UIExplorer/js/NativeAnimationsExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Tester extends React.Component {
4949
this.current && this.props.reverseConfig ? this.props.reverseConfig : this.props.config
5050
);
5151
this.current = this.current ? 0 : 1;
52-
const config = {
52+
const config: Object = {
5353
...animConfig,
5454
toValue: this.current,
5555
};

Examples/UIExplorer/js/ScrollViewExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ exports.examples = [
7171
description: 'You can display <ScrollView>\'s child components horizontally rather than vertically',
7272
render: function() {
7373

74-
function renderScrollView(title: string, addtionalStyles: StyleSheet) {
74+
function renderScrollView(title: string, addtionalStyles: typeof StyleSheet) {
7575
var _scrollView: ScrollView;
7676
return (
7777
<View style={addtionalStyles}>

Libraries/Components/Picker/Picker.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,44 @@ var pickerStyleType = StyleSheetPropType({
3333
var MODE_DIALOG = 'dialog';
3434
var MODE_DROPDOWN = 'dropdown';
3535

36+
/**
37+
* Individual selectable item in a Picker.
38+
*/
39+
class PickerItem extends React.Component {
40+
props: {
41+
label: string,
42+
value?: any,
43+
color?: ColorPropType,
44+
testID?: string,
45+
};
46+
47+
static propTypes = {
48+
/**
49+
* Text to display for this item.
50+
*/
51+
label: React.PropTypes.string.isRequired,
52+
/**
53+
* The value to be passed to picker's `onValueChange` callback when
54+
* this item is selected. Can be a string or an integer.
55+
*/
56+
value: React.PropTypes.any,
57+
/**
58+
* Color of this item's text.
59+
* @platform android
60+
*/
61+
color: ColorPropType,
62+
/**
63+
* Used to locate the item in end-to-end tests.
64+
*/
65+
testID: React.PropTypes.string,
66+
};
67+
68+
render() {
69+
// The items are not rendered directly
70+
throw null;
71+
}
72+
}
73+
3674
/**
3775
* Renders the native picker component on iOS and Android. Example:
3876
*
@@ -65,6 +103,8 @@ class Picker extends React.Component {
65103
*/
66104
static MODE_DROPDOWN = MODE_DROPDOWN;
67105

106+
static Item = PickerItem;
107+
68108
static defaultProps = {
69109
mode: MODE_DIALOG,
70110
};
@@ -127,43 +167,4 @@ class Picker extends React.Component {
127167
}
128168
}
129169

130-
/**
131-
* Individual selectable item in a Picker.
132-
*/
133-
// $FlowFixMe found when converting React.createClass to ES6
134-
Picker.Item = class extends React.Component {
135-
props: {
136-
label: string,
137-
value?: any,
138-
color?: ColorPropType,
139-
testID?: string,
140-
};
141-
142-
static propTypes = {
143-
/**
144-
* Text to display for this item.
145-
*/
146-
label: React.PropTypes.string.isRequired,
147-
/**
148-
* The value to be passed to picker's `onValueChange` callback when
149-
* this item is selected. Can be a string or an integer.
150-
*/
151-
value: React.PropTypes.any,
152-
/**
153-
* Color of this item's text.
154-
* @platform android
155-
*/
156-
color: ColorPropType,
157-
/**
158-
* Used to locate the item in end-to-end tests.
159-
*/
160-
testID: React.PropTypes.string,
161-
};
162-
163-
render() {
164-
// The items are not rendered directly
165-
throw null;
166-
}
167-
};
168-
169170
module.exports = Picker;

Libraries/Experimental/SwipeableRow/SwipeableListView.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const SwipeableRow = require('SwipeableRow');
1818

1919
const {PropTypes} = React;
2020

21+
type DefaultProps = {
22+
bounceFirstRowOnMount: boolean,
23+
renderQuickActions: Function,
24+
};
25+
2126
type Props = {
2227
bounceFirstRowOnMount: boolean,
2328
dataSource: SwipeableListViewDataSource,
@@ -49,7 +54,7 @@ type State = {
4954
* - It can bounce the 1st row of the list so users know it's swipeable
5055
* - More to come
5156
*/
52-
class SwipeableListView extends React.Component {
57+
class SwipeableListView extends React.Component<DefaultProps, Props, State> {
5358
props: Props;
5459
state: State;
5560

Libraries/Image/Image.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ var Image = React.createClass({
194194
getSize(
195195
url: string,
196196
success: (width: number, height: number) => void,
197-
failure: (error: any) => void,
197+
failure?: (error: any) => void,
198198
) {
199199
return ImageLoader.getSize(url)
200200
.then(function(sizes) {

Libraries/Image/Image.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const Image = React.createClass({
304304
getSize: function(
305305
uri: string,
306306
success: (width: number, height: number) => void,
307-
failure: (error: any) => void,
307+
failure?: (error: any) => void,
308308
) {
309309
ImageViewManager.getSize(uri, success, failure || function() {
310310
console.warn('Failed to get size for image: ' + uri);

Libraries/react-native/react-native-implementation.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,11 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
99
* @providesModule react-native-implementation
10-
* @noflow - get/set properties not yet supported by flow. also `...require(x)` is broken #6560135
10+
* @flow
1111
*/
1212
'use strict';
1313

1414
const invariant = require('fbjs/lib/invariant');
15-
const warning = require('fbjs/lib/warning');
16-
17-
if (__DEV__) {
18-
var warningDedupe = {};
19-
var addonWarn = function(prevName, newPackageName) {
20-
warning(
21-
warningDedupe[prevName],
22-
'React.addons.' + prevName + ' is deprecated. Please import the "' +
23-
newPackageName + '" package instead.'
24-
);
25-
warningDedupe[prevName] = true;
26-
};
27-
}
2815

2916
// Export React, plus some native additions.
3017
const ReactNative = {
@@ -118,6 +105,7 @@ const ReactNative = {
118105
get Platform() { return require('Platform'); },
119106
get processColor() { return require('processColor'); },
120107
get requireNativeComponent() { return require('requireNativeComponent'); },
108+
get takeSnapshot() { return require('takeSnapshot'); },
121109

122110
// Prop Types
123111
get ColorPropType() { return require('ColorPropType'); },
@@ -133,7 +121,6 @@ const ReactNative = {
133121
'and imported from `react-native-deprecated-custom-components` instead of `react-native`. ' +
134122
'Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html'
135123
);
136-
return null;
137124
},
138125
};
139126

0 commit comments

Comments
 (0)