From af76ebd531d80c1641b4bc3a4af6f6dc473d7784 Mon Sep 17 00:00:00 2001 From: Yangfan Huang Date: Tue, 29 Dec 2015 17:19:08 +0800 Subject: [PATCH] Support auto pagination --- GiftedListView.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/GiftedListView.js b/GiftedListView.js index d20321b..bc1d54d 100644 --- a/GiftedListView.js +++ b/GiftedListView.js @@ -44,6 +44,7 @@ var GiftedListView = React.createClass({ headerView: null, sectionHeaderView: null, withSections: false, + autoPaginate: false, onFetch(page, callback, options) { callback([]); }, paginationFetchigView: null, @@ -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, @@ -216,6 +218,14 @@ var GiftedListView = React.createClass({ ); }, + onEndReached() { + if (this.props.autoPaginate) { + this._onPaginate(); + } + if (this.props.onEndReached) { + this.props.onEndReached(); + } + }, getInitialState() { @@ -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 = {}) { @@ -418,6 +431,8 @@ var GiftedListView = React.createClass({ renderSeparator={this.renderSeparator} + onEndReached={this.onEndReached} + {...this.props} style={[this.props.style, style]}