Replace get with iterator and remove lambda

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-07-16 14:19:48 +05:30
parent f366479c16
commit 9fdfebf00d

View file

@ -118,6 +118,17 @@ export class LazyListView extends ListView {
return array; return array;
} }
_itemAtIndex(idx) {
let i = 0;
for (const item of this._list) {
if (i === idx) {
return item;
}
i = i + 1;
}
return null;
}
_renderElementsInRange() { _renderElementsInRange() {
const { topCount, renderCount, bottomCount } = this._renderRange; const { topCount, renderCount, bottomCount } = this._renderRange;
const paddingTop = topCount * this._itemHeight; const paddingTop = topCount * this._itemHeight;
@ -196,18 +207,17 @@ export class LazyListView extends ListView {
_renderAdditionalElement(fromIdx, toIdx) { _renderAdditionalElement(fromIdx, toIdx) {
const {topCount, renderCount} = this._renderRange; const {topCount, renderCount} = this._renderRange;
const childFromIndex = index => this._childCreator(this._list.get(index));
if (toIdx < fromIdx) { if (toIdx < fromIdx) {
// Element is moved up the list, so render element from top boundary // Element is moved up the list, so render element from top boundary
const index = topCount; const index = topCount;
const child = childFromIndex(index); const child = this._childCreator(this._itemAtIndex(index));
this._childInstances.unshift(child); this._childInstances.unshift(child);
this._root.insertBefore(mountView(child, this._mountArgs), this._root.firstChild); this._root.insertBefore(mountView(child, this._mountArgs), this._root.firstChild);
} }
else { else {
// Element is moved down the list, so render element from bottom boundary // Element is moved down the list, so render element from bottom boundary
const index = topCount + renderCount - 1; const index = topCount + renderCount - 1;
const child = childFromIndex(index); const child = this._childCreator(this._itemAtIndex(index));
this._childInstances.push(child); this._childInstances.push(child);
this._root.appendChild(mountView(child, this._mountArgs)); this._root.appendChild(mountView(child, this._mountArgs));
} }