Skip to content

Commit 243ede0

Browse files
committed
Setup flow
1 parent c1a14b6 commit 243ede0

5 files changed

Lines changed: 91 additions & 18 deletions

File tree

.flowconfig

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
11+
; Ignore duplicate module providers
12+
; For RN Apps installed via npm, "Libraries" folder is inside
13+
; "node_modules/react-native" but in the source repo it is in the root
14+
.*/Libraries/react-native/React.js
15+
.*/Libraries/react-native/ReactNative.js
16+
17+
.*/node_modules/react-navigation
18+
19+
; Do not remove all example to have react-native
20+
.*/example/main.js
21+
.*/example/Pages/.*
22+
23+
; Remove duplication between example and .
24+
.*/example/node_modules/fbjs/
25+
26+
; Remove not passing libs
27+
.*/example/node_modules/react-native-tab-view/
28+
29+
[include]
30+
31+
[libs]
32+
example/node_modules/react-native/Libraries/react-native/react-native-interface.js
33+
example/node_modules/react-native/flow
34+
flow/
35+
36+
[options]
37+
emoji=true
38+
39+
module.system=haste
40+
41+
munge_underscores=true
42+
43+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
44+
45+
suppress_type=$FlowIssue
46+
suppress_type=$FlowFixMe
47+
suppress_type=$FixMe
48+
49+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
50+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
51+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
52+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
53+
54+
unsafe.enable_getters_and_setters=true
55+
56+
[version]
57+
^0.47.0

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "src/index.js",
66
"scripts": {
77
"lint": "eslint src/*.js",
8-
"test": "npm run lint",
8+
"test": "npm run lint && flow",
99
"prettify": "prettier --single-quote --trailing-comma es5 --print-width 100 --write src/**.js"
1010
},
1111
"files": ["README.md", "LICENCE", "src", "readmeAssets"],
@@ -39,6 +39,7 @@
3939
"eslint-plugin-jsx-a11y": "^4.0.0",
4040
"eslint-plugin-prettier": "2.1.2",
4141
"eslint-plugin-react": "^6.10.0",
42+
"flow-bin": "^0.47.0",
4243
"prettier": "^1.5.3",
4344
"react": "16.0.0-alpha.12"
4445
},

src/ImageHeaderScrollView.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
// @flow weak
12
import React, { Component } from 'react';
23
import { Animated, ScrollView, StyleSheet, View } from 'react-native';
34
import _ from 'lodash';
45

5-
const SCROLLVIEW_REF = 'ScrollView';
6-
76
const styles = StyleSheet.create({
87
container: {
98
flex: 1,
@@ -40,7 +39,10 @@ const styles = StyleSheet.create({
4039
},
4140
});
4241

43-
class ImageHeaderScrollView extends Component {
42+
class ImageHeaderScrollView extends Component<*, *, *> {
43+
container: *;
44+
scrollViewRef: ScrollView;
45+
4446
constructor(props) {
4547
super(props);
4648
this.state = {
@@ -61,7 +63,7 @@ class ImageHeaderScrollView extends Component {
6163
* with any component that expects a `ScrollView`.
6264
*/
6365
getScrollResponder() {
64-
return this[SCROLLVIEW_REF].getScrollResponder();
66+
return this.scrollViewRef.getScrollResponder();
6567
}
6668
getScrollableNode() {
6769
return this.getScrollResponder().getScrollableNode();
@@ -70,7 +72,7 @@ class ImageHeaderScrollView extends Component {
7072
return this.getScrollResponder().getInnerViewNode();
7173
}
7274
setNativeProps(props) {
73-
this[SCROLLVIEW_REF].setNativeProps(props);
75+
this.scrollViewRef.setNativeProps(props);
7476
}
7577
scrollTo(...args) {
7678
this.getScrollResponder().scrollTo(...args);
@@ -187,7 +189,7 @@ class ImageHeaderScrollView extends Component {
187189
{this.renderHeader()}
188190
<Animated.View style={[styles.container, { transform: [{ translateY: topMargin }] }]}>
189191
<ScrollView
190-
ref={ref => (this[SCROLLVIEW_REF] = ref)}
192+
ref={ref => (this.scrollViewRef = ref)}
191193
style={styles.container}
192194
scrollEventThrottle={16}
193195
onScroll={Animated.event([
@@ -208,8 +210,8 @@ class ImageHeaderScrollView extends Component {
208210
}
209211

210212
ImageHeaderScrollView.propTypes = {
211-
children: React.PropTypes.node || React.PropTypes.nodes,
212-
childrenStyle: View.propTypes.style,
213+
children: React.PropTypes.node || React.PropTypes.arrayOf(React.PropTypes.node),
214+
childrenStyle: React.PropTypes.any,
213215
overlayColor: React.PropTypes.string,
214216
fadeOutForeground: React.PropTypes.bool,
215217
foregroundParallaxRatio: React.PropTypes.number,

src/TriggeringView.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
// @flow weak
12
import React, { Component } from 'react';
23
import { View, Animated } from 'react-native';
34
import _ from 'lodash';
45

5-
class TriggeringView extends Component {
6+
class TriggeringView extends Component<*, *, *> {
7+
initialPageY: number;
8+
listenerId: number;
9+
ref: *;
10+
height: number;
11+
12+
onScroll: Function;
13+
onRef: Function;
14+
onLayout: Function;
15+
616
constructor(props) {
717
super(props);
818
this.state = {
919
touched: false,
1020
hidden: false,
1121
};
1222
this.initialPageY = 0;
13-
this.onScroll = this.onScroll.bind(this);
14-
this.onRef = this.onRef.bind(this);
15-
this.onLayout = this.onLayout.bind(this);
23+
this.onScroll = this._onScroll.bind(this);
24+
this.onRef = this._onRef.bind(this);
25+
this.onLayout = this._onLayout.bind(this);
1626
}
1727

1828
componentWillMount() {
@@ -30,19 +40,19 @@ class TriggeringView extends Component {
3040
nextContext.scrollY.addListener(this.onScroll);
3141
}
3242

33-
onRef(ref) {
43+
_onRef(ref) {
3444
this.ref = ref;
3545
}
3646

37-
onLayout(e) {
47+
_onLayout(e) {
3848
const layout = e.nativeEvent.layout;
3949
this.height = layout.height;
4050
this.ref.measure((x, y, width, height, pageX, pageY) => {
4151
this.initialPageY = pageY;
4252
});
4353
}
4454

45-
onScroll(event) {
55+
_onScroll(event) {
4656
const pageY = this.initialPageY - event.value;
4757
this.triggerEvents(this.context.scrollPageY, pageY, pageY + this.height);
4858
}
@@ -70,7 +80,7 @@ class TriggeringView extends Component {
7080
}
7181

7282
render() {
73-
const viewProps = _.pick(this.props, _.keys(View.propTypes));
83+
const viewProps = _.omit(this.props, _.keys(TriggeringView.propTypes));
7484
return (
7585
<View ref={this.onRef} onLayout={this.onLayout} collapsable={false} {...viewProps}>
7686
{this.props.children}
@@ -85,7 +95,6 @@ TriggeringView.propTypes = {
8595
onDisplay: React.PropTypes.func,
8696
onTouchTop: React.PropTypes.func,
8797
onTouchBottom: React.PropTypes.func,
88-
...View.propTypes,
8998
};
9099

91100
TriggeringView.defaultProps = {

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,10 @@ flat-cache@^1.2.1:
915915
graceful-fs "^4.1.2"
916916
write "^0.2.1"
917917

918+
flow-bin@^0.47.0:
919+
version "0.47.0"
920+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.47.0.tgz#a2a08ab3e0d1f1cb57d17e27b30b118b62fda367"
921+
918922
foreach@^2.0.5:
919923
version "2.0.5"
920924
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"

0 commit comments

Comments
 (0)