Fix lastIndex

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-16 15:28:57 +05:30 committed by Bruno Windels
parent bbeb909bdc
commit d625d57aa4
2 changed files with 5 additions and 5 deletions

View file

@ -37,7 +37,7 @@ export class ItemRange {
}
containsIndex(idx) {
return idx >= this.topCount && idx < this.lastIndex;
return idx >= this.topCount && idx <= this.lastIndex;
}
expand(amount) {
@ -56,7 +56,7 @@ export class ItemRange {
}
get lastIndex() {
return this.topCount + this.renderCount;
return this.topCount + this.renderCount - 1;
}
totalSize() {
@ -105,7 +105,7 @@ export class ItemRange {
return {toRemove, toAdd, scrollDirection};
}
const bisection1 = {start: Math.min(this.topCount, range.topCount), end: Math.max(this.topCount, range.topCount) - 1};
const bisection2 = {start: Math.min(this.lastIndex, range.lastIndex), end: Math.max(this.lastIndex, range.lastIndex)};
const bisection2 = {start: Math.min(this.lastIndex, range.lastIndex) + 1, end: Math.max(this.lastIndex, range.lastIndex)};
// When scrolling down, bisection1 needs to be removed and bisection2 needs to be added
// When scrolling up, vice versa
const toRemove = scrollDirection === ScrollDirection.downwards ? bisection1 : bisection2;

View file

@ -73,7 +73,7 @@ export class LazyListView extends ListView {
const array = [];
let i = 0;
for (const item of this._list) {
if (i >= start && i < end) {
if (i >= start && i <= end) {
array.push(item);
}
i = i + 1;
@ -201,7 +201,7 @@ export class LazyListView extends ListView {
this._renderRange = new ItemRange(topCount, renderCount - 1, bottomCount);
}
else {
const child = this._childCreator(this._itemAtIndex(this._renderRange.lastIndex - 1));
const child = this._childCreator(this._itemAtIndex(this._renderRange.lastIndex));
this._childInstances.push(child);
this._root.appendChild(mountView(child, this._mountArgs));
this._renderRange = new ItemRange(topCount, renderCount, bottomCount - 1);