Skip to content

Commit b6cf798

Browse files
committed
remove PropsType and use last version of flow
1 parent 4962b57 commit b6cf798

File tree

6 files changed

+2992
-143
lines changed

6 files changed

+2992
-143
lines changed

.flowconfig

+6-11
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
1717
.*/node_modules/react-navigation
1818

1919
; 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/
20+
.*/example/.*
2821

2922
[include]
3023

@@ -44,14 +37,16 @@ module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|we
4437

4538
suppress_type=$FlowIssue
4639
suppress_type=$FlowFixMe
40+
suppress_type=$FlowFixMeProps
41+
suppress_type=$FlowFixMeState
4742
suppress_type=$FixMe
4843

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]+
44+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
45+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
5146
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
5247
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
5348

5449
unsafe.enable_getters_and_setters=true
5550

5651
[version]
57-
^0.47.0
52+
^0.53.0

example/yarn.lock

+4-3
Original file line numberDiff line numberDiff line change
@@ -3338,11 +3338,12 @@ react-native-drawer-layout@1.3.2:
33383338
dependencies:
33393339
react-native-dismiss-keyboard "1.0.0"
33403340

3341-
react-native-image-header-scroll-view@^0.6.1:
3342-
version "0.6.1"
3343-
resolved "https://registry.yarnpkg.com/react-native-image-header-scroll-view/-/react-native-image-header-scroll-view-0.6.1.tgz#84beba8acbef69761a4e8c15bb0c18a011598d11"
3341+
react-native-image-header-scroll-view@^0.6.2:
3342+
version "0.6.2"
3343+
resolved "https://registry.yarnpkg.com/react-native-image-header-scroll-view/-/react-native-image-header-scroll-view-0.6.2.tgz#ed4a367bbf4d89c984faca833073509ce198c13b"
33443344
dependencies:
33453345
lodash "^4.17.4"
3346+
prop-types "^15.5.10"
33463347

33473348
react-native-tab-view@^0.0.65:
33483349
version "0.0.65"

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
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",
42+
"flow-bin": "^0.53.0",
4343
"prettier": "^1.5.3",
44-
"react": "16.0.0-alpha.12"
44+
"react": "16.0.0-beta.5",
45+
"react-native": "0.49.5"
4546
},
4647
"peerDependencies": {
4748
"react": ">=15.3.1",
4849
"react-native": ">=0.20.0"
4950
},
5051
"dependencies": {
51-
"lodash": "^4.17.4",
52-
"prop-types": "^15.5.10"
52+
"lodash": "^4.17.4"
5353
}
5454
}

src/ImageHeaderScrollView.js

+40-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Animated, ScrollView, StyleSheet, View } from 'react-native';
55
import _ from 'lodash';
66

77
export type Props = {
8-
children: React.Element<any>,
8+
children: React$Element<any>,
99
childrenStyle: any,
1010
overlayColor: string,
1111
fadeOutForeground: boolean,
@@ -14,10 +14,10 @@ export type Props = {
1414
maxOverlayOpacity: number,
1515
minHeight: number,
1616
minOverlayOpacity: number,
17-
renderFixedForeground: () => React.Element<any>,
18-
renderForeground: () => React.Element<any>,
19-
renderHeader: () => React.Element<any>,
20-
renderTouchableFixedForeground: () => React.Element<any>,
17+
renderFixedForeground: () => React$Element<any>,
18+
renderForeground: () => React$Element<any>,
19+
renderHeader: () => React$Element<any>,
20+
renderTouchableFixedForeground: () => React$Element<any>,
2121
};
2222

2323
export type DefaultProps = {
@@ -28,19 +28,19 @@ export type DefaultProps = {
2828
maxOverlayOpacity: number,
2929
minHeight: number,
3030
minOverlayOpacity: number,
31-
renderFixedForeground: () => React.Element<any>,
32-
renderForeground: () => React.Element<any>,
33-
renderHeader: () => React.Element<any>,
31+
renderFixedForeground: () => React$Element<any>,
32+
renderForeground: () => React$Element<any>,
33+
renderHeader: () => React$Element<any>,
3434
};
3535

3636
export type State = {
3737
scrollY: Animated.Value,
3838
pageY: number,
3939
};
4040

41-
class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
42-
container: *;
43-
scrollViewRef: ScrollView;
41+
class ImageHeaderScrollView extends Component<Props, State> {
42+
container: ?any; // @see https://github.com/facebook/react-native/issues/15955
43+
scrollViewRef: ?any; // @see https://github.com/facebook/react-native/issues/15955
4444
state: State;
4545

4646
static defaultProps: DefaultProps = {
@@ -76,19 +76,37 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
7676
* with any component that expects a `ScrollView`.
7777
*/
7878
getScrollResponder() {
79+
if (!this.scrollViewRef) {
80+
return;
81+
}
7982
return this.scrollViewRef.getScrollResponder();
8083
}
8184
getScrollableNode() {
82-
return this.getScrollResponder().getScrollableNode();
85+
const responder = this.getScrollResponder();
86+
if (!responder) {
87+
return;
88+
}
89+
return responder.getScrollableNode();
8390
}
8491
getInnerViewNode() {
85-
return this.getScrollResponder().getInnerViewNode();
92+
const responder = this.getScrollResponder();
93+
if (!responder) {
94+
return;
95+
}
96+
return responder.getInnerViewNode();
8697
}
8798
setNativeProps(props: Props) {
99+
if (!this.scrollViewRef) {
100+
return;
101+
}
88102
this.scrollViewRef.setNativeProps(props);
89103
}
90104
scrollTo(...args: *) {
91-
this.getScrollResponder().scrollTo(...args);
105+
const responder = this.getScrollResponder();
106+
if (!responder) {
107+
return;
108+
}
109+
responder.scrollTo(...args);
92110
}
93111

94112
interpolateOnImageHeight(outputRange: Array<number>) {
@@ -178,6 +196,13 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
178196
);
179197
}
180198

199+
onContainerLayout = () => {
200+
if (!this.container) {
201+
return;
202+
}
203+
this.container.measureInWindow((x, y) => this.setState(() => ({ pageY: y })));
204+
};
205+
181206
render() {
182207
const {
183208
children,
@@ -209,7 +234,7 @@ class ImageHeaderScrollView extends Component<DefaultProps, Props, State> {
209234
<View
210235
style={styles.container}
211236
ref={ref => (this.container = ref)}
212-
onLayout={() => this.container.measureInWindow((x, y) => this.setState({ pageY: y }))}
237+
onLayout={this.onContainerLayout}
213238
>
214239
{this.renderHeader()}
215240
<Animated.View style={[styles.container, { transform: [{ translateY: topMargin }] }]}>

src/TriggeringView.js

+62-43
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
11
// @flow weak
22
import React, { Component } from 'react';
3-
import PropTypes from 'prop-types';
43
import { View, Animated } from 'react-native';
54
import _ from 'lodash';
65

7-
class TriggeringView extends Component<*, *, *> {
6+
type Props = {
7+
onBeginHidden: Function,
8+
onHide: Function,
9+
onBeginDisplayed: Function,
10+
onDisplay: Function,
11+
onTouchTop: Function,
12+
onTouchBottom: Function,
13+
children?: React$Node,
14+
};
15+
16+
type DefaultProps = {
17+
onBeginHidden: Function,
18+
onHide: Function,
19+
onBeginDisplayed: Function,
20+
onDisplay: Function,
21+
onTouchTop: Function,
22+
onTouchBottom: Function,
23+
};
24+
25+
type State = {
26+
touched: boolean,
27+
hidden: boolean,
28+
};
29+
30+
type Context = {
31+
scrollPageY?: number,
32+
scrollY: Animated.Value,
33+
};
34+
35+
class TriggeringView extends Component<Props, State> {
836
initialPageY: number;
9-
listenerId: number;
10-
ref: *;
37+
listenerId: string;
38+
ref: ?any; // @see https://github.com/facebook/react-native/issues/15955
1139
height: number;
40+
context: Context;
1241

1342
onScroll: Function;
1443
onRef: Function;
1544
onLayout: Function;
45+
state: State = {
46+
touched: false,
47+
hidden: false,
48+
};
49+
50+
static defaultProps: DefaultProps = {
51+
onBeginHidden: () => {},
52+
onHide: () => {},
53+
onBeginDisplayed: () => {},
54+
onDisplay: () => {},
55+
onTouchTop: () => {},
56+
onTouchBottom: () => {},
57+
};
1658

1759
constructor(props) {
1860
super(props);
19-
this.state = {
20-
touched: false,
21-
hidden: false,
22-
};
2361
this.initialPageY = 0;
24-
this.onScroll = this._onScroll.bind(this);
25-
this.onRef = this._onRef.bind(this);
26-
this.onLayout = this._onLayout.bind(this);
2762
}
2863

2964
componentWillMount() {
@@ -41,40 +76,46 @@ class TriggeringView extends Component<*, *, *> {
4176
nextContext.scrollY.addListener(this.onScroll);
4277
}
4378

44-
_onRef(ref) {
79+
onRef = ref => {
4580
this.ref = ref;
46-
}
81+
};
4782

48-
_onLayout(e) {
83+
onLayout = e => {
84+
if (!this.ref) {
85+
return;
86+
}
4987
const layout = e.nativeEvent.layout;
5088
this.height = layout.height;
5189
this.ref.measure((x, y, width, height, pageX, pageY) => {
5290
this.initialPageY = pageY;
5391
});
54-
}
92+
};
5593

56-
_onScroll(event) {
94+
onScroll = event => {
95+
if (!this.context.scrollPageY) {
96+
return;
97+
}
5798
const pageY = this.initialPageY - event.value;
5899
this.triggerEvents(this.context.scrollPageY, pageY, pageY + this.height);
59-
}
100+
};
60101

61102
triggerEvents(value, top, bottom) {
62103
if (!this.state.touched && value >= top) {
63-
this.setState({ touched: true });
104+
this.setState(() => ({ touched: true }));
64105
this.props.onBeginHidden();
65106
this.props.onTouchTop(true);
66107
} else if (this.state.touched && value < top) {
67-
this.setState({ touched: false });
108+
this.setState(() => ({ touched: false }));
68109
this.props.onDisplay();
69110
this.props.onTouchTop(false);
70111
}
71112

72113
if (!this.state.hidden && value >= bottom) {
73-
this.setState({ hidden: true });
114+
this.setState(() => ({ hidden: true }));
74115
this.props.onHide();
75116
this.props.onTouchBottom(true);
76117
} else if (this.state.hidden && value < bottom) {
77-
this.setState({ hidden: false });
118+
this.setState(() => ({ hidden: false }));
78119
this.props.onBeginDisplayed();
79120
this.props.onTouchBottom(false);
80121
}
@@ -89,27 +130,5 @@ class TriggeringView extends Component<*, *, *> {
89130
);
90131
}
91132
}
92-
TriggeringView.propTypes = {
93-
onBeginHidden: PropTypes.func,
94-
onHide: PropTypes.func,
95-
onBeginDisplayed: PropTypes.func,
96-
onDisplay: PropTypes.func,
97-
onTouchTop: PropTypes.func,
98-
onTouchBottom: PropTypes.func,
99-
};
100-
101-
TriggeringView.defaultProps = {
102-
onBeginHidden: () => {},
103-
onHide: () => {},
104-
onBeginDisplayed: () => {},
105-
onDisplay: () => {},
106-
onTouchTop: () => {},
107-
onTouchBottom: () => {},
108-
};
109-
110-
TriggeringView.contextTypes = {
111-
scrollY: PropTypes.instanceOf(Animated.Value),
112-
scrollPageY: PropTypes.number,
113-
};
114133

115134
export default TriggeringView;

0 commit comments

Comments
 (0)