Skip to content

Commit

Permalink
Support auto pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangfan Huang committed Dec 29, 2015
1 parent 907326f commit af76ebd
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions GiftedListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var GiftedListView = React.createClass({
headerView: null,
sectionHeaderView: null,
withSections: false,
autoPaginate: false,
onFetch(page, callback, options) { callback([]); },

paginationFetchigView: null,
Expand Down Expand Up @@ -72,6 +73,7 @@ var GiftedListView = React.createClass({
headerView: React.PropTypes.func,
sectionHeaderView: React.PropTypes.func,
withSections: React.PropTypes.bool,
autoPaginate: React.PropTypes.bool,
onFetch: React.PropTypes.func,

paginationFetchigView: React.PropTypes.func,
Expand Down Expand Up @@ -216,6 +218,14 @@ var GiftedListView = React.createClass({
<View style={[this.defaultStyles.separator, this.props.customStyles.separator]} />
);
},
onEndReached() {
if (this.props.autoPaginate) {
this._onPaginate();
}
if (this.props.onEndReached) {
this.props.onEndReached();
}
},

getInitialState() {

Expand Down Expand Up @@ -286,10 +296,13 @@ var GiftedListView = React.createClass({
},

_onPaginate() {
this.setState({
paginationStatus: 'fetching',
});
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
if (this.state.paginationStatus === 'firstLoad'
|| this.state.paginationStatus === 'waiting') {
this.setState({
paginationStatus: 'fetching',
});
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
}
},

_postPaginate(rows = [], options = {}) {
Expand Down Expand Up @@ -418,6 +431,8 @@ var GiftedListView = React.createClass({

renderSeparator={this.renderSeparator}

onEndReached={this.onEndReached}

{...this.props}

style={[this.props.style, style]}
Expand Down

0 comments on commit af76ebd

Please sign in to comment.