[ListView] Update curRenderedRowsCount when data source changes
Summary: When a new data source is provided, update `curRenderedRowsCount` in addition to `prevRenderedRowsCount`. What was happening is that I had an empty data source, so `curRenderedRowsCount` and `prevRenderedRowsCount` both settled at zero after the first few frames and `curRenderedRowsCount` wasn't getting increased when the data source was updated. I also changed the `setState` calls to use the transactional API since several of the new state values are computed from the old ones. Maybe fixes #1547 Closes https://github.com/facebook/react-native/pull/1612 Github Author: James Ide <ide@jameside.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
parent
e2fc7d2362
commit
3393b86534
|
@ -262,7 +262,16 @@ var ListView = React.createClass({
|
|||
|
||||
componentWillReceiveProps: function(nextProps) {
|
||||
if (this.props.dataSource !== nextProps.dataSource) {
|
||||
this.setState({prevRenderedRowsCount: 0});
|
||||
this.setState((state, props) => {
|
||||
var rowsToRender = Math.min(
|
||||
state.curRenderedRowsCount + props.pageSize,
|
||||
props.dataSource.getRowCount()
|
||||
);
|
||||
return {
|
||||
prevRenderedRowsCount: 0,
|
||||
curRenderedRowsCount: rowsToRender,
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -412,22 +421,21 @@ var ListView = React.createClass({
|
|||
},
|
||||
|
||||
_pageInNewRows: function() {
|
||||
this.setState((state, props) => {
|
||||
var rowsToRender = Math.min(
|
||||
this.state.curRenderedRowsCount + this.props.pageSize,
|
||||
this.props.dataSource.getRowCount()
|
||||
state.curRenderedRowsCount + props.pageSize,
|
||||
props.dataSource.getRowCount()
|
||||
);
|
||||
this.setState(
|
||||
{
|
||||
prevRenderedRowsCount: this.state.curRenderedRowsCount,
|
||||
return {
|
||||
prevRenderedRowsCount: state.curRenderedRowsCount,
|
||||
curRenderedRowsCount: rowsToRender
|
||||
},
|
||||
() => {
|
||||
};
|
||||
}, () => {
|
||||
this._measureAndUpdateScrollProps();
|
||||
this.setState({
|
||||
prevRenderedRowsCount: this.state.curRenderedRowsCount,
|
||||
this.setState(state => ({
|
||||
prevRenderedRowsCount: state.curRenderedRowsCount,
|
||||
}));
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
_getDistanceFromEnd: function(scrollProperties) {
|
||||
|
|
Loading…
Reference in New Issue