diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index c37ae0f0b072c6..3cfc63bcf43865 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -613,7 +613,6 @@ export default class VirtualizedList extends StateSafePureComponent< const onEndReachedThreshold = onEndReachedThresholdOrDefault( props.onEndReachedThreshold, ); - this._updateViewableItems(props, cellsAroundViewport); const {contentLength, offset, visibleLength} = this._scrollMetrics; const distanceFromEnd = contentLength - visibleLength - offset; @@ -1125,7 +1124,7 @@ export default class VirtualizedList extends StateSafePureComponent< } } - componentDidUpdate(prevProps: Props) { + componentDidUpdate(prevProps: Props, prevState: State) { const {data, extraData} = this.props; if (data !== prevProps.data || extraData !== prevProps.extraData) { // clear the viewableIndices cache to also trigger @@ -1147,6 +1146,15 @@ export default class VirtualizedList extends StateSafePureComponent< if (hiPriInProgress) { this._hiPriInProgress = false; } + + // Make sure to cancel any pending updates if maintainVisibleContentPositionAdjustment + // changed since they are now invalid. + if ( + prevState.maintainVisibleContentPositionAdjustment !== + this.state.maintainVisibleContentPositionAdjustment + ) { + this._updateCellsToRenderBatcher.dispose({abort: true}); + } } _averageCellLength = 0; @@ -1787,6 +1795,8 @@ export default class VirtualizedList extends StateSafePureComponent< }; _updateCellsToRender = () => { + this._updateViewableItems(this.props, this.state.cellsAroundViewport); + this.setState((state, props) => { const cellsAroundViewport = this._adjustCellsAroundViewport( props,