Skip to content

Commit c8d5e09

Browse files
committed
Fix top and bottom cells special cases
1 parent acec8ef commit c8d5e09

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/components/virtual-scroll/virtual-util.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function processRecords(stopAtHeight: number,
1717
records: any[], cells: VirtualCell[],
1818
headerFn: Function, footerFn: Function,
1919
data: VirtualData) {
20+
console.debug('virtual-util-processRecords', 'cells before processing are:', cells);
2021
let record: any;
2122
let startRecordIndex: number;
2223
let previousCell: VirtualCell;
@@ -79,6 +80,7 @@ export function processRecords(stopAtHeight: number,
7980
if (previousCell.top + previousCell.height + data.itmHeight > stopAtHeight && processedTotal > 3) {
8081
return;
8182
}
83+
console.debug('virtual-util-processRecords', 'cells after processing are:', cells);
8284
}
8385
}
8486

@@ -464,7 +466,11 @@ export function adjustRendered(cells: VirtualCell[], data: VirtualData) {
464466
data.topCell = Math.max(data.topViewCell - viewableRenderedPadding, 0);
465467
data.bottomCell = Math.min(data.topCell + 2, totalCells - 1);
466468

467-
for (var i = data.topCell; i < totalCells; i++) {
469+
console.debug('virtualScroll-util', 'before scrolling down, will render cells:', data.topCell, 'to', data.bottomCell,
470+
'totalCells are:', totalCells, 'renderHeight is now', cellsRenderHeight, 'viewableRenderedPadding', viewableRenderedPadding,
471+
'topViewCell:', data.topViewCell, 'bottomViewCell:', data.bottomViewCell);
472+
473+
for (let i = data.topCell; i < totalCells; i++) {
468474
cell = cells[i];
469475
if (cell.row !== lastRow) {
470476
cellsRenderHeight += cell.height;
@@ -480,6 +486,29 @@ export function adjustRendered(cells: VirtualCell[], data: VirtualData) {
480486
}
481487
}
482488

489+
if (data.bottomCell === totalCells - 1) {
490+
let tempHeight = 0;
491+
lastRow = -1;
492+
for (let i = data.bottomCell; i >= 0; i--) {
493+
cell = cells[i];
494+
if (cell.row !== lastRow) {
495+
tempHeight += cell.height;
496+
lastRow = cell.row;
497+
}
498+
499+
if (i < data.topCell) {
500+
data.topCell = i;
501+
}
502+
503+
if (tempHeight >= maxRenderHeight) {
504+
break;
505+
}
506+
}
507+
}
508+
console.debug('virtualScroll-util', 'after scrolling down, will render cells:', data.topCell, 'to', data.bottomCell,
509+
'totalCells are:', totalCells, 'renderHeight is now', cellsRenderHeight, 'viewableRenderedPadding', viewableRenderedPadding,
510+
'topViewCell:', data.topViewCell, 'bottomViewCell:', data.bottomViewCell);
511+
483512
} else {
484513
// scroll up
485514
data.bottomCell = Math.min(data.bottomViewCell + viewableRenderedPadding, totalCells - 1);
@@ -500,6 +529,29 @@ export function adjustRendered(cells: VirtualCell[], data: VirtualData) {
500529
break;
501530
}
502531
}
532+
533+
if (data.topCell === 0) {
534+
let tempHeight = 0;
535+
lastRow = -1;
536+
for (let i = data.topCell; i < totalCells; i++) {
537+
cell = cells[i];
538+
if (cell.row !== lastRow) {
539+
tempHeight += cell.height;
540+
lastRow = cell.row;
541+
}
542+
543+
if (i > data.bottomCell) {
544+
data.bottomCell = i;
545+
}
546+
547+
if (tempHeight >= maxRenderHeight) {
548+
break;
549+
}
550+
}
551+
}
552+
console.debug('virtualScroll-util', 'scrolling up, will render cells:', data.topCell, 'to', data.bottomCell,
553+
'totalCells are:', totalCells, 'renderHeight is now', cellsRenderHeight, 'viewableRenderedPadding', viewableRenderedPadding,
554+
'topViewCell:', data.topViewCell, 'bottomViewCell:', data.bottomViewCell);
503555
}
504556
}
505557

0 commit comments

Comments
 (0)