Skip to content

Commit e59a1d2

Browse files
fallintoplacemeta-codesync[bot]
authored andcommitted
fix(virtualized-lists): invalidate content length on orientation change (#57871)
Summary: When a list changes between vertical and horizontal layouts, `ListMetricsAggregator` resets its cell measurements but keeps `_contentLength`. That value belongs to the old scrolling axis. In horizontal RTL mode, it can then be used to calculate a cell offset before the new content layout is observed. This clears `_contentLength` during horizontal orientation changes so RTL calculations wait for the new content length. The reset was present in the original orientation invalidation logic and was removed when bottom-up layout support was removed. ## Changelog: [GENERAL] [FIXED] - Invalidate list content length when orientation changes. Pull Request resolved: #57871 Test Plan: - Added regression coverage for vertical to horizontal content length invalidation. - Verified horizontal RTL metrics throw until new content layout is observed. - Ran `yarn jest packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js --runInBand`. - Ran Prettier and targeted ESLint checks. Reviewed By: christophpurrer Differential Revision: D115586644 Pulled By: fabriziocucci fbshipit-source-id: 6c0f1b435575c080444b72381f7ce56ae3f69a15
1 parent 7f18ad0 commit e59a1d2

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

packages/virtualized-lists/Lists/ListMetricsAggregator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export default class ListMetricsAggregator {
319319
if (orientation.horizontal !== this._orientation.horizontal) {
320320
this._cellMetrics.clear();
321321
this._averageCellLength = 0;
322+
this._contentLength = null;
322323
this._highestMeasuredCellIndex = 0;
323324
this._measuredCellsLength = 0;
324325
this._measuredCellsCount = 0;

packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,43 @@ describe('ListMetricsAggregator', () => {
986986
expect(listMetrics.getContentLength()).toBe(25);
987987
});
988988

989+
it('invalidates content length when list orientation changes', () => {
990+
const listMetrics = new ListMetricsAggregator();
991+
const verticalOrientation = {horizontal: false, rtl: false};
992+
const horizontalOrientation = {horizontal: true, rtl: false};
993+
const horizontalRtlOrientation = {horizontal: true, rtl: true};
994+
const cellLayout = {height: 50, width: 100, x: 0, y: 0};
995+
996+
listMetrics.notifyListContentLayout({
997+
layout: {height: 800, width: 400},
998+
orientation: verticalOrientation,
999+
});
1000+
expect(listMetrics.hasContentLength()).toBe(true);
1001+
1002+
listMetrics.notifyCellLayout({
1003+
cellIndex: 0,
1004+
cellKey: '0',
1005+
orientation: horizontalOrientation,
1006+
layout: cellLayout,
1007+
});
1008+
expect(listMetrics.hasContentLength()).toBe(false);
1009+
1010+
expect(() =>
1011+
listMetrics.notifyCellLayout({
1012+
cellIndex: 0,
1013+
cellKey: '0',
1014+
orientation: horizontalRtlOrientation,
1015+
layout: cellLayout,
1016+
}),
1017+
).toThrow();
1018+
1019+
listMetrics.notifyListContentLayout({
1020+
layout: {height: 50, width: 500},
1021+
orientation: horizontalRtlOrientation,
1022+
});
1023+
expect(listMetrics.getContentLength()).toBe(500);
1024+
});
1025+
9891026
it('requires contentLength to resolve RTL metrics', () => {
9901027
const listMetrics = new ListMetricsAggregator();
9911028
const orientation = {horizontal: true, rtl: true};

0 commit comments

Comments
 (0)