Fix ListView bug where onEndReached wouldn't trigger initially

Summary: @​public

Sometimes we want to load a very small number of rows initially and want the
onEndReached callback to be called immediately to trigger more data to be
loaded without waiting for the  user to scroll at all.  This diff makes that
happen by also checking on mount instead of only when scrolling.

Reviewed By: @vjeux

Differential Revision: D2507184

fb-gh-sync-id: ea8e47667d00387a935a426dd45afe978fd6d8cd
This commit is contained in:
Spencer Ahrens 2015-10-05 13:42:25 -07:00 committed by facebook-github-bot-0
parent d409f13abe
commit b0bdd4e45d
1 changed files with 14 additions and 8 deletions

View File

@ -452,10 +452,23 @@ var ListView = React.createClass({
this._updateVisibleRows(childFrames);
},
_maybeCallOnEndReached: function(event) {
if (this.props.onEndReached &&
this.scrollProperties.contentLength !== this._sentEndForContentLength &&
this._getDistanceFromEnd(this.scrollProperties) < this.props.onEndReachedThreshold &&
this.state.curRenderedRowsCount === this.props.dataSource.getRowCount()) {
this._sentEndForContentLength = this.scrollProperties.contentLength;
this.props.onEndReached(event);
return true;
}
return false;
},
_renderMoreRowsIfNeeded: function() {
if (this.scrollProperties.contentLength === null ||
this.scrollProperties.visibleLength === null ||
this.state.curRenderedRowsCount === this.props.dataSource.getRowCount()) {
this._maybeCallOnEndReached();
return;
}
@ -570,14 +583,7 @@ var ListView = React.createClass({
isVertical ? 'y' : 'x'
];
this._updateVisibleRows(e.nativeEvent.updatedChildFrames);
var nearEnd = this._getDistanceFromEnd(this.scrollProperties) < this.props.onEndReachedThreshold;
if (nearEnd &&
this.props.onEndReached &&
this.scrollProperties.contentLength !== this._sentEndForContentLength &&
this.state.curRenderedRowsCount === this.props.dataSource.getRowCount()) {
this._sentEndForContentLength = this.scrollProperties.contentLength;
this.props.onEndReached(e);
} else {
if (!this._maybeCallOnEndReached(e)) {
this._renderMoreRowsIfNeeded();
}