Skip to content

Commit 8781263

Browse files
author
Bas Pellis
committed
All ScrollView properties are exposed now. Removed wrapping View.
1 parent eec3483 commit 8781263

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Simple Calendar example included.
1717
![react-native-infinite-scrollview demo](https://raw.githubusercontent.com/baspellis/react-native-infinite-scrollview/master/example/video/demo.gif)
1818

1919
### API
20+
Component wraps ScrollView so all ScrollView properties are available.
2021
- **renderPage** - Required - (Function) - Must return a component representing the page for the provided index.
21-
- **horizontal** - Optional - (Boolean) - Scroll horizontal instead of vertical (default).
2222
- **offScreenPages** - Optional - (Integer) - Number of pages to render before and after the current page. Default is 1 (total 3 pages are rendered).
2323
- **index** - Optional - (Integer) - Start the scrollview with this index. Default is 0 or toIndex whichever is greater.
2424
- **toIndex** - Optional - (Integer) - Don't allow scrolling below this page index

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"dependencies": {
99
"moment": "^2.11.2",
1010
"react-native": "^0.20.0",
11-
"react-native-infinite-scrollview": "^0.2.0"
11+
"react-native-infinite-scrollview": "^0.2.1"
1212
}
1313
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-infinite-scrollview",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "ScrollView with infinte paged scrolling (no looping). The number of pages rendered before and after current page can be customized. Pages are rendered when user scrolled.",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,36 @@ export default class InfiniteScrollView extends Component {
5151
pages = this._createPages(range);
5252
}
5353
return (
54-
<View style={this.props.style} onLayout={(event) => this._layoutChanged(event)}>
55-
<ScrollView
56-
style={{overflow: 'visible'}}
57-
ref={(scrollView) => { this._scrollView = scrollView; }}
58-
horizontal={this.props.horizontal}
59-
automaticallyAdjustContentInsets={false}
60-
showsHorizontalScrollIndicator={false}
61-
showsVerticalScrollIndicator={false}
62-
pagingEnabled={true}
63-
onMomentumScrollEnd={(e) => this._scrollEnded(e)}>
64-
{pages}
65-
</ScrollView>
66-
</View>
54+
<ScrollView
55+
{...this.props}
56+
ref={(scrollView) => {this._scrollView = scrollView}}
57+
onLayout={(e) => this._layoutChanged(e)}
58+
pagingEnabled={true}
59+
onMomentumScrollEnd={(e) => this._onMomentumScrollEnd(e)}>
60+
{pages}
61+
</ScrollView>
6762
);
6863
}
6964
_layoutChanged(event) {
7065
var {x, y, width, height} = event.nativeEvent.layout;
71-
7266
this.setState({
7367
size: {
7468
width: width,
7569
height: height
7670
}
7771
});
72+
if(this.props.onLayout) {
73+
this.props.onLayout(event);
74+
}
75+
}
76+
_onMomentumScrollEnd(event) {
77+
var scrollIndex = Math.round(this.props.horizontal ? event.nativeEvent.contentOffset.x / this.state.size.width : event.nativeEvent.contentOffset.y / this.state.size.height);
78+
var index = this.state.index + scrollIndex - Math.min(this._offscreenPages, this.state.index - this.state.fromIndex) - Math.max(0, this._offscreenPages + this.state.index - this.state.toIndex);
79+
this.setState({index: index});
80+
81+
if(this.props.onMomentumScrollEnd) {
82+
this.props.onMomentumScrollEnd(event);
83+
}
7884
}
7985
_pagesRange(state) {
8086
var range = {};
@@ -98,9 +104,4 @@ export default class InfiniteScrollView extends Component {
98104
</View>
99105
);
100106
}
101-
_scrollEnded(event) {
102-
var scrollIndex = Math.round(this.props.horizontal ? event.nativeEvent.contentOffset.x / this.state.size.width : event.nativeEvent.contentOffset.y / this.state.size.height);
103-
var index = this.state.index + scrollIndex - Math.min(this._offscreenPages, this.state.index - this.state.fromIndex) - Math.max(0, this._offscreenPages + this.state.index - this.state.toIndex);
104-
this.setState({index: index});
105-
}
106107
}

0 commit comments

Comments
 (0)