Fix lastIndex
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
bbeb909bdc
commit
d625d57aa4
2 changed files with 5 additions and 5 deletions
|
@ -37,7 +37,7 @@ export class ItemRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
containsIndex(idx) {
|
containsIndex(idx) {
|
||||||
return idx >= this.topCount && idx < this.lastIndex;
|
return idx >= this.topCount && idx <= this.lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand(amount) {
|
expand(amount) {
|
||||||
|
@ -56,7 +56,7 @@ export class ItemRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
get lastIndex() {
|
get lastIndex() {
|
||||||
return this.topCount + this.renderCount;
|
return this.topCount + this.renderCount - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalSize() {
|
totalSize() {
|
||||||
|
@ -105,7 +105,7 @@ export class ItemRange {
|
||||||
return {toRemove, toAdd, scrollDirection};
|
return {toRemove, toAdd, scrollDirection};
|
||||||
}
|
}
|
||||||
const bisection1 = {start: Math.min(this.topCount, range.topCount), end: Math.max(this.topCount, range.topCount) - 1};
|
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 down, bisection1 needs to be removed and bisection2 needs to be added
|
||||||
// When scrolling up, vice versa
|
// When scrolling up, vice versa
|
||||||
const toRemove = scrollDirection === ScrollDirection.downwards ? bisection1 : bisection2;
|
const toRemove = scrollDirection === ScrollDirection.downwards ? bisection1 : bisection2;
|
||||||
|
|
|
@ -73,7 +73,7 @@ export class LazyListView extends ListView {
|
||||||
const array = [];
|
const array = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const item of this._list) {
|
for (const item of this._list) {
|
||||||
if (i >= start && i < end) {
|
if (i >= start && i <= end) {
|
||||||
array.push(item);
|
array.push(item);
|
||||||
}
|
}
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
|
@ -201,7 +201,7 @@ export class LazyListView extends ListView {
|
||||||
this._renderRange = new ItemRange(topCount, renderCount - 1, bottomCount);
|
this._renderRange = new ItemRange(topCount, renderCount - 1, bottomCount);
|
||||||
}
|
}
|
||||||
else {
|
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._childInstances.push(child);
|
||||||
this._root.appendChild(mountView(child, this._mountArgs));
|
this._root.appendChild(mountView(child, this._mountArgs));
|
||||||
this._renderRange = new ItemRange(topCount, renderCount, bottomCount - 1);
|
this._renderRange = new ItemRange(topCount, renderCount, bottomCount - 1);
|
||||||
|
|
Reference in a new issue