From 0f84b5bc8d07d08337c9d59daf966ebe2e560a95 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 16 Mar 2023 19:02:39 -0400 Subject: [PATCH 1/2] Fix batched rendering when mcvp adjustment changes --- Libraries/Lists/VirtualizedList.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index c37ae0f0b072..cc60ee54b2f5 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1125,7 +1125,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 +1147,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; From 3bf2583e7415928ef6ebac7c48fe94c9c0880551 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 16 Mar 2023 19:06:27 -0400 Subject: [PATCH 2/2] Avoid VirtualizedList viewability updates during state updates --- Libraries/Lists/VirtualizedList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index cc60ee54b2f5..3cfc63bcf438 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; @@ -1796,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,