Skip to content

Commit 8036fd9

Browse files
committed
fix(virtualized-lists): invalidate content length on orientation change
1 parent 2660348 commit 8036fd9

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)