Skip to content

Commit af76ebd

Browse files
author
Yangfan Huang
committed
Support auto pagination
1 parent 907326f commit af76ebd

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

GiftedListView.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var GiftedListView = React.createClass({
4444
headerView: null,
4545
sectionHeaderView: null,
4646
withSections: false,
47+
autoPaginate: false,
4748
onFetch(page, callback, options) { callback([]); },
4849

4950
paginationFetchigView: null,
@@ -72,6 +73,7 @@ var GiftedListView = React.createClass({
7273
headerView: React.PropTypes.func,
7374
sectionHeaderView: React.PropTypes.func,
7475
withSections: React.PropTypes.bool,
76+
autoPaginate: React.PropTypes.bool,
7577
onFetch: React.PropTypes.func,
7678

7779
paginationFetchigView: React.PropTypes.func,
@@ -216,6 +218,14 @@ var GiftedListView = React.createClass({
216218
<View style={[this.defaultStyles.separator, this.props.customStyles.separator]} />
217219
);
218220
},
221+
onEndReached() {
222+
if (this.props.autoPaginate) {
223+
this._onPaginate();
224+
}
225+
if (this.props.onEndReached) {
226+
this.props.onEndReached();
227+
}
228+
},
219229

220230
getInitialState() {
221231

@@ -286,10 +296,13 @@ var GiftedListView = React.createClass({
286296
},
287297

288298
_onPaginate() {
289-
this.setState({
290-
paginationStatus: 'fetching',
291-
});
292-
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
299+
if (this.state.paginationStatus === 'firstLoad'
300+
|| this.state.paginationStatus === 'waiting') {
301+
this.setState({
302+
paginationStatus: 'fetching',
303+
});
304+
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
305+
}
293306
},
294307

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

419432
renderSeparator={this.renderSeparator}
420433

434+
onEndReached={this.onEndReached}
435+
421436
{...this.props}
422437

423438
style={[this.props.style, style]}

0 commit comments

Comments
 (0)