Skip to content

Commit 564ef41

Browse files
committed
Recalculated nodes once more on scrollEnd
1 parent bfa44b9 commit 564ef41

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,15 @@ export class VirtualScroll implements DoCheck, OnChanges, AfterContentInit, OnDe
735735
// ******** DOM READ ****************
736736
updateDimensions(this._plt, this._nodes, this._cells, this._data, false);
737737
adjustRendered(this._cells, this._data);
738+
populateNodeData(
739+
this._data.topCell, this._data.bottomCell,
740+
true,
741+
this._cells, this._records, this._nodes,
742+
this._itmTmp.viewContainer,
743+
this._itmTmp.templateRef,
744+
this._hdrTmp && this._hdrTmp.templateRef,
745+
this._ftrTmp && this._ftrTmp.templateRef
746+
);
738747

739748
// ******** DOM WRITE ***************
740749
this._dom.write(() => {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EmbeddedViewRef, TemplateRef, ViewContainerRef } from '@angular/core';
2+
import { assert } from '../../util/util';
23

34
import { Platform } from '../../platform/platform';
45

@@ -17,7 +18,6 @@ export function processRecords(stopAtHeight: number,
1718
records: any[], cells: VirtualCell[],
1819
headerFn: Function, footerFn: Function,
1920
data: VirtualData) {
20-
console.debug('virtual-util-processRecords', 'cells before processing are:', cells);
2121
let record: any;
2222
let startRecordIndex: number;
2323
let previousCell: VirtualCell;
@@ -80,7 +80,6 @@ export function processRecords(stopAtHeight: number,
8080
if (previousCell.top + previousCell.height + data.itmHeight > stopAtHeight && processedTotal > 3) {
8181
return;
8282
}
83-
console.debug('virtual-util-processRecords', 'cells after processing are:', cells);
8483
}
8584
}
8685

@@ -137,15 +136,14 @@ export function populateNodeData(startCellIndex: number, endCellIndex: number, s
137136
startCellIndex = Math.max(startCellIndex, 0);
138137
endCellIndex = Math.min(endCellIndex, cells.length - 1);
139138

140-
const usedNodes: any[] = [];
139+
const usedNodes: VirtualNode[] = [];
141140
for (var cellIndex = startCellIndex; cellIndex <= endCellIndex; cellIndex++) {
142141
cell = cells[cellIndex];
143142
availableNode = null;
144143

145144
// find the first one that's available
146145
const existingNode = nodes.find(n => n.cell === cellIndex && n.tmpl === cell.tmpl);
147146
if (existingNode) {
148-
console.debug('virtual-util', 'found that cell is already rendered in existingNode', existingNode);
149147
if (existingNode.view.context.$implicit === records[cell.record]) {
150148
usedNodes.push(existingNode);
151149
continue; // optimization: node data is the same no need to update
@@ -241,6 +239,8 @@ export function populateNodeData(startCellIndex: number, endCellIndex: number, s
241239
const removeIndex = nodes.findIndex(n => n === node);
242240
nodes.splice(removeIndex, 1);
243241
});
242+
usedNodes.length = 0;
243+
unusedNodes.length = 0;
244244

245245
return hasChanges;
246246
}
@@ -338,7 +338,6 @@ export function updateDimensions(plt: Platform, nodes: VirtualNode[], cells: Vir
338338
cell.row++;
339339
cell.top = (previousCell.top + previousCell.height);
340340
cell.left = 0;
341-
342341
} else {
343342
// same row
344343
cell.row = previousCell.row;
@@ -356,7 +355,6 @@ export function updateDimensions(plt: Platform, nodes: VirtualNode[], cells: Vir
356355
previousCell = cell;
357356
}
358357
}
359-
360358
}
361359

362360

@@ -477,6 +475,7 @@ export function adjustRendered(cells: VirtualCell[], data: VirtualData) {
477475
data.topCell = data.bottomCell;
478476

479477
let cellsRenderHeight = 0;
478+
assert(data.bottomCell > 0, 'bottomCell should be greater than 0');
480479
for (let i = data.bottomCell; i >= 0; i--) {
481480
cellsRenderHeight += cells[i].height;
482481
if (i < data.topCell) data.topCell = i;

0 commit comments

Comments
 (0)