Skip to content

Commit 03d521b

Browse files
committed
Fix TriggeringView
1 parent a58edd3 commit 03d521b

File tree

7 files changed

+341
-264
lines changed

7 files changed

+341
-264
lines changed

.flowconfig

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
; For RN Apps installed via npm, "Libraries" folder is inside
1313
; "node_modules/react-native" but in the source repo it is in the root
1414
.*/Libraries/react-native/React.js
15-
.*/Libraries/react-native/ReactNative.js
1615

17-
.*/node_modules/react-navigation
18-
19-
; Do not remove all example to have react-native
20-
.*/example/.*
16+
; Ignore metro
17+
.*/node_modules/metro/.*
2118

2219
[include]
2320

2421
[libs]
25-
example/node_modules/react-native/Libraries/react-native/react-native-interface.js
26-
example/node_modules/react-native/flow
22+
node_modules/react-native/Libraries/react-native/react-native-interface.js
23+
node_modules/react-native/flow/
24+
node_modules/react-native/flow-github/
2725
flow/
2826

2927
[options]
@@ -35,18 +33,23 @@ munge_underscores=true
3533

3634
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'
3735

36+
module.file_ext=.js
37+
module.file_ext=.jsx
38+
module.file_ext=.json
39+
module.file_ext=.native.js
40+
3841
suppress_type=$FlowIssue
3942
suppress_type=$FlowFixMe
4043
suppress_type=$FlowFixMeProps
4144
suppress_type=$FlowFixMeState
4245
suppress_type=$FixMe
4346

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]+
47+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
4649
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
4750
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
4851

4952
unsafe.enable_getters_and_setters=true
5053

5154
[version]
52-
^0.53.0
55+
^0.61.0

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"trailingComma": "es5",
3+
"singleQuote": true,
4+
"bracketSpacing": true,
5+
"tabWidth": 2,
6+
"printWidth": 100
7+
}

package.json

Lines changed: 5 additions & 5 deletions
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.53.0",
43-
"prettier": "^1.5.3",
44-
"react": "16.0.0-beta.5",
45-
"react-native": "0.49.5"
42+
"flow-bin": "^0.61.0",
43+
"prettier": "^1.10.2",
44+
"react": "16.2.0",
45+
"react-native": "0.52.2"
4646
},
4747
"peerDependencies": {
4848
"react": ">=15.3.1",
4949
"react-native": ">=0.20.0"
5050
},
5151
"dependencies": {
52-
"lodash": "^4.17.4"
52+
"prop-types": "^15.6.0"
5353
}
5454
}

src/ImageHeaderScrollView.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import React, { Component } from 'react';
33
import PropTypes from 'prop-types';
44
import { Animated, ScrollView, StyleSheet, View } from 'react-native';
5-
import _ from 'lodash';
65

76
export type Props = {
87
children?: ?React$Element<any>,
@@ -144,9 +143,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
144143
<Animated.View style={[styles.header, headerTransformStyle]}>
145144
{this.props.renderHeader()}
146145
<Animated.View style={overlayStyle} />
147-
<View style={styles.fixedForeground}>
148-
{this.props.renderFixedForeground()}
149-
</View>
146+
<View style={styles.fixedForeground}>{this.props.renderFixedForeground()}</View>
150147
</Animated.View>
151148
);
152149
}
@@ -247,9 +244,7 @@ class ImageHeaderScrollView extends Component<Props, State> {
247244
])}
248245
{...scrollViewProps}
249246
>
250-
<Animated.View style={childrenContainerStyle}>
251-
{children}
252-
</Animated.View>
247+
<Animated.View style={childrenContainerStyle}>{children}</Animated.View>
253248
</ScrollView>
254249
</Animated.View>
255250
{this.renderTouchableFixedForeground()}

src/TriggeringView.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// @flow weak
1+
// @flow
22
import React, { Component } from 'react';
3+
import PropTypes from 'prop-types';
34
import { View, Animated } from 'react-native';
4-
import _ from 'lodash';
55

66
type Props = {
77
onBeginHidden: Function,
@@ -11,6 +11,7 @@ type Props = {
1111
onTouchTop: Function,
1212
onTouchBottom: Function,
1313
children?: React$Node,
14+
onLayout?: Function,
1415
};
1516

1617
type DefaultProps = {
@@ -56,7 +57,7 @@ class TriggeringView extends Component<Props, State> {
5657
onTouchBottom: () => {},
5758
};
5859

59-
constructor(props) {
60+
constructor(props: Props) {
6061
super(props);
6162
this.initialPageY = 0;
6263
}
@@ -68,19 +69,22 @@ class TriggeringView extends Component<Props, State> {
6869
this.listenerId = this.context.scrollY.addListener(this.onScroll);
6970
}
7071

71-
componentWillReceiveProps(nextProps, nextContext) {
72+
componentWillReceiveProps(nextProps: Props, nextContext: Context) {
7273
if (!this.context.scrollY) {
7374
return;
7475
}
7576
this.context.scrollY.removeListener(this.listenerId);
7677
nextContext.scrollY.addListener(this.onScroll);
7778
}
7879

79-
onRef = ref => {
80+
onRef = (ref: any) => {
8081
this.ref = ref;
8182
};
8283

83-
onLayout = e => {
84+
onLayout = (e: *) => {
85+
if (this.props.onLayout) {
86+
this.props.onLayout(e);
87+
}
8488
if (!this.ref) {
8589
return;
8690
}
@@ -91,44 +95,57 @@ class TriggeringView extends Component<Props, State> {
9195
});
9296
};
9397

94-
onScroll = event => {
98+
onScroll = (event: *) => {
9599
if (!this.context.scrollPageY) {
96100
return;
97101
}
98102
const pageY = this.initialPageY - event.value;
99103
this.triggerEvents(this.context.scrollPageY, pageY, pageY + this.height);
100104
};
101105

102-
triggerEvents(value, top, bottom) {
106+
triggerEvents(value: number, top: number, bottom: number) {
103107
if (!this.state.touched && value >= top) {
104-
this.setState(() => ({ touched: true }));
108+
this.setState({ touched: true });
105109
this.props.onBeginHidden();
106110
this.props.onTouchTop(true);
107111
} else if (this.state.touched && value < top) {
108-
this.setState(() => ({ touched: false }));
112+
this.setState({ touched: false });
109113
this.props.onDisplay();
110114
this.props.onTouchTop(false);
111115
}
112116

113117
if (!this.state.hidden && value >= bottom) {
114-
this.setState(() => ({ hidden: true }));
118+
this.setState({ hidden: true });
115119
this.props.onHide();
116120
this.props.onTouchBottom(true);
117121
} else if (this.state.hidden && value < bottom) {
118-
this.setState(() => ({ hidden: false }));
122+
this.setState({ hidden: false });
119123
this.props.onBeginDisplayed();
120124
this.props.onTouchBottom(false);
121125
}
122126
}
123127

124128
render() {
125-
const viewProps = _.omit(this.props, _.keys(TriggeringView.propTypes));
129+
const {
130+
onBeginHidden,
131+
onHide,
132+
onBeginDisplayed,
133+
onDisplay,
134+
onTouchTop,
135+
onTouchBottom,
136+
...viewProps
137+
} = this.props;
126138
return (
127-
<View ref={this.onRef} onLayout={this.onLayout} collapsable={false} {...viewProps}>
139+
<View ref={this.onRef} collapsable={false} {...viewProps} onLayout={this.onLayout}>
128140
{this.props.children}
129141
</View>
130142
);
131143
}
132144
}
133145

146+
TriggeringView.contextTypes = {
147+
scrollY: PropTypes.instanceOf(Animated.Value),
148+
scrollPageY: PropTypes.number,
149+
};
150+
134151
export default TriggeringView;

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// @flow
12
export { default } from './ImageHeaderScrollView';
23
export { default as TriggeringView } from './TriggeringView';

0 commit comments

Comments
 (0)