fix listview inefficiency for tail-fetching scenarios (part2)

Reviewed By: sahrens

Differential Revision: D2775293

fb-gh-sync-id: a18a2fd6f64b5c979267a21ecdac8c3d97d9e007
This commit is contained in:
olivier notteghem 2015-12-19 17:12:56 -08:00 committed by facebook-github-bot-8
parent 97fe0eae6b
commit 174d37c1d9
1 changed files with 7 additions and 13 deletions

View File

@ -248,7 +248,6 @@ var ListView = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
curRenderedRowsCount: this.props.initialListSize, curRenderedRowsCount: this.props.initialListSize,
prevRenderedRowsCount: 0,
highlightedRow: {}, highlightedRow: {},
}; };
}, },
@ -266,6 +265,7 @@ var ListView = React.createClass({
}; };
this._childFrames = []; this._childFrames = [];
this._visibleRows = {}; this._visibleRows = {};
this._prevRenderedRowsCount = 0;
}, },
componentDidMount: function() { componentDidMount: function() {
@ -283,8 +283,8 @@ var ListView = React.createClass({
state.curRenderedRowsCount + props.pageSize, state.curRenderedRowsCount + props.pageSize,
props.dataSource.getRowCount() props.dataSource.getRowCount()
); );
this._prevRenderedRowsCount = 0;
return { return {
prevRenderedRowsCount: 0,
curRenderedRowsCount: rowsToRender, curRenderedRowsCount: rowsToRender,
}; };
}); });
@ -321,7 +321,7 @@ var ListView = React.createClass({
} }
if (this.props.renderSectionHeader) { if (this.props.renderSectionHeader) {
var shouldUpdateHeader = rowCount >= this.state.prevRenderedRowsCount && var shouldUpdateHeader = rowCount >= this._prevRenderedRowsCount &&
dataSource.sectionHeaderShouldUpdate(sectionIdx); dataSource.sectionHeaderShouldUpdate(sectionIdx);
bodyComponents.push( bodyComponents.push(
<StaticRenderer <StaticRenderer
@ -340,7 +340,7 @@ var ListView = React.createClass({
for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
var rowID = rowIDs[rowIdx]; var rowID = rowIDs[rowIdx];
var comboID = sectionID + '_' + rowID; var comboID = sectionID + '_' + rowID;
var shouldUpdateRow = rowCount >= this.state.prevRenderedRowsCount && var shouldUpdateRow = rowCount >= this._prevRenderedRowsCount &&
dataSource.rowShouldUpdate(sectionIdx, rowIdx); dataSource.rowShouldUpdate(sectionIdx, rowIdx);
var row = var row =
<StaticRenderer <StaticRenderer
@ -427,7 +427,7 @@ var ListView = React.createClass({
RCTScrollViewManager && RCTScrollViewManager.calculateChildFrames && RCTScrollViewManager && RCTScrollViewManager.calculateChildFrames &&
RCTScrollViewManager.calculateChildFrames( RCTScrollViewManager.calculateChildFrames(
React.findNodeHandle(scrollComponent), React.findNodeHandle(scrollComponent),
this._updateChildFrames, this._updateVisibleRows,
); );
}, },
@ -459,10 +459,6 @@ var ListView = React.createClass({
this._renderMoreRowsIfNeeded(); this._renderMoreRowsIfNeeded();
}, },
_updateChildFrames: function(childFrames) {
this._updateVisibleRows(childFrames);
},
_maybeCallOnEndReached: function(event) { _maybeCallOnEndReached: function(event) {
if (this.props.onEndReached && if (this.props.onEndReached &&
this.scrollProperties.contentLength !== this._sentEndForContentLength && this.scrollProperties.contentLength !== this._sentEndForContentLength &&
@ -495,15 +491,13 @@ var ListView = React.createClass({
state.curRenderedRowsCount + props.pageSize, state.curRenderedRowsCount + props.pageSize,
props.dataSource.getRowCount() props.dataSource.getRowCount()
); );
this._prevRenderedRowsCount = state.curRenderedRowsCount;
return { return {
prevRenderedRowsCount: state.curRenderedRowsCount,
curRenderedRowsCount: rowsToRender curRenderedRowsCount: rowsToRender
}; };
}, () => { }, () => {
this._measureAndUpdateScrollProps(); this._measureAndUpdateScrollProps();
this.setState(state => ({ this._prevRenderedRowsCount = this.state.curRenderedRowsCount;
prevRenderedRowsCount: state.curRenderedRowsCount,
}));
}); });
}, },