Skip to content

Commit f7216b7

Browse files
committed
ScrollView compatible
1 parent d7f674b commit f7216b7

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ render() {
3838
}
3939
```
4040

41+
## Usage (API)
42+
43+
All of the properties of `ScrollView` are supported. Please refer to the
44+
[`ScrollView` documentation](https://facebook.github.io/react-native/docs/scrollview.html) for more detail.
45+
4146
## Other open-source modules by the folks at [BAM](http://github.com/bamlab)
4247

4348
* [generator-rn-toolbox](https://github.com/bamlab/generator-rn-toolbox)

exemple/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"@exponent/vector-icons": "~2.0.3",
1010
"exponent": "~12.0.3",
11+
"lodash": "^4.17.4",
1112
"react": "~15.3.2",
1213
"react-native": "git+https://github.com/exponentjs/react-native#sdk-12.0.0",
1314
"react-native-image-header-scroll-view": "^0.0.2"

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@
5454
"modulePathIgnorePatterns": [
5555
"<rootDir>/exemple/"
5656
]
57+
},
58+
"dependencies": {
59+
"lodash": "^4.17.4"
5760
}
5861
}

src/__tests__/__snapshots__/index.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports[`test renders correctly by default 1`] = `
1+
exports[`ImageHeaderScrollView renders correctly by default 1`] = `
22
<View
33
style={
44
Object {

src/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
StyleSheet,
66
View,
77
} from 'react-native';
8+
import _ from 'lodash';
9+
10+
const SCROLLVIEW_REF = 'ScrollView';
811

912
const styles = StyleSheet.create({
1013
container: {
@@ -41,6 +44,27 @@ class ImageHeaderScrollView extends Component {
4144
};
4245
}
4346

47+
/*
48+
* Expose `ScrollView` API so this component is composable
49+
* with any component that expects a `ScrollView`.
50+
*/
51+
getScrollResponder() {
52+
return this[SCROLLVIEW_REF].getScrollResponder();
53+
}
54+
getScrollableNode() {
55+
return this.getScrollResponder().getScrollableNode();
56+
}
57+
getInnerViewNode() {
58+
return this.getScrollResponder().getInnerViewNode();
59+
}
60+
setNativeProps(props) {
61+
this[SCROLLVIEW_REF].setNativeProps(props);
62+
}
63+
scrollTo(...args) {
64+
this.getScrollResponder().scrollTo(...args);
65+
}
66+
67+
4468
interpolateOnImageHeight(outputRange) {
4569
const headerScrollDistance = this.props.maxHeight - this.props.minHeight;
4670
return this.state.scrollY.interpolate({
@@ -96,14 +120,17 @@ class ImageHeaderScrollView extends Component {
96120
}
97121

98122
render() {
123+
const scrollViewProps = _.pick(this.props, _.keys(ScrollView.propTypes));
99124
return (
100125
<View style={styles.container}>
101126
<ScrollView
127+
ref={(sv) => { this[SCROLLVIEW_REF] = sv; }}
102128
style={styles.container}
103129
scrollEventThrottle={16}
104130
onScroll={Animated.event(
105131
[{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }],
106132
)}
133+
{...scrollViewProps}
107134
>
108135
<Animated.View style={[{ paddingTop: this.props.maxHeight }, this.props.childrenStyle]}>
109136
{this.props.children}
@@ -127,6 +154,7 @@ ImageHeaderScrollView.propTypes = {
127154
childrenStyle: View.propTypes.style,
128155
foregroundParallaxRatio: React.PropTypes.number,
129156
fadeOutForeground: React.PropTypes.bool,
157+
...ScrollView.propTypes,
130158
};
131159

132160
ImageHeaderScrollView.defaultProps = {

0 commit comments

Comments
 (0)