fix(virtual-scroll): fixes dynamic changes

This commit is contained in:
Manu MA
2018-12-19 00:27:04 +01:00
committed by GitHub
parent 320eb03168
commit d1cecf142b
11 changed files with 234 additions and 99 deletions

View File

@ -55,18 +55,18 @@ export class VirtualScroll implements ComponentInterface {
* app's CSS, whereas this approximation is used to help calculate
* initial dimensions before the item has been rendered.
*/
@Prop() approxHeaderHeight = 40;
@Prop() approxHeaderHeight = 30;
/**
* The approximate width of each footer template's cell.
* This dimension is used to help determine how many cells should
* be created when initialized, and to help calculate the height of
* the scrollable area. This value can use either `px` or `%` units.
* the scrollable area. This height value can only use `px` units.
* Note that the actual rendered size of each cell comes from the
* app's CSS, whereas this approximation is used to help calculate
* initial dimensions before the item has been rendered.
*/
@Prop() approxFooterHeight = 40;
@Prop() approxFooterHeight = 30;
/**
* Section headers and the data used within its given
@ -190,7 +190,7 @@ export class VirtualScroll implements ComponentInterface {
* The subset of items to be updated can are specifing by an offset and a length.
*/
@Method()
markDirty(offset: number, len = -1) {
checkRange(offset: number, len = -1) {
// TODO: kind of hacky how we do in-place updated of the cells
// array. this part needs a complete refactor
if (!this.items) {
@ -200,18 +200,7 @@ export class VirtualScroll implements ComponentInterface {
? this.items.length - offset
: len;
const max = this.lastItemLen;
let j = 0;
if (offset > 0 && offset < max) {
j = findCellIndex(this.cells, offset);
} else if (offset === 0) {
j = 0;
} else if (offset === max) {
j = this.cells.length;
} else {
console.warn('bad values for markDirty');
return;
}
const cellIndex = findCellIndex(this.cells, offset);
const cells = calcCells(
this.items,
this.itemHeight,
@ -220,10 +209,10 @@ export class VirtualScroll implements ComponentInterface {
this.approxHeaderHeight,
this.approxFooterHeight,
this.approxItemHeight,
j, offset, length
cellIndex, offset, length
);
console.debug('[virtual] cells recalculated', cells.length);
this.cells = inplaceUpdate(this.cells, cells, offset);
this.cells = inplaceUpdate(this.cells, cells, cellIndex);
this.lastItemLen = this.items.length;
this.indexDirty = Math.max(offset - 1, 0);
@ -235,15 +224,14 @@ export class VirtualScroll implements ComponentInterface {
*
* It's equivalent to calling:
*
* ```
* virtualScroll.markDirty(lastItemLen, items.length - lastItemLen);
* ```js
* virtualScroll.checkRange(lastItemLen);
* ```
*/
@Method()
markDirtyTail() {
checkEnd() {
if (this.items) {
const offset = this.lastItemLen;
this.markDirty(offset, this.items.length - offset);
this.checkRange(this.lastItemLen);
}
}