Make code clearer

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

View file

@ -205,7 +205,10 @@ export class LazyListView extends ListView {
} }
} }
_renderAdditionalElement(fromIdx, toIdx) { /**
* Render additional element from top or bottom to offset the outgoing element
*/
_renderExtraOnMove(fromIdx, toIdx) {
const {topCount, renderCount} = this._renderRange; const {topCount, renderCount} = this._renderRange;
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
@ -223,7 +226,10 @@ export class LazyListView extends ListView {
} }
} }
_removeAdditionalElement(fromIdx, toIdx) { /**
* Remove an element from top or bottom to make space for the incoming element
*/
_removeElementOnMove(fromIdx, toIdx) {
// If element comes from the bottom, remove element at bottom and vice versa // If element comes from the bottom, remove element at bottom and vice versa
const child = toIdx < fromIdx ? this._childInstances.pop() : this._childInstances.shift(); const child = toIdx < fromIdx ? this._childInstances.pop() : this._childInstances.shift();
this._removeChild(child); this._removeChild(child);
@ -241,13 +247,13 @@ export class LazyListView extends ListView {
this.onBeforeListChanged(); this.onBeforeListChanged();
const [child] = this._childInstances.splice(normalizedFromIdx, 1); const [child] = this._childInstances.splice(normalizedFromIdx, 1);
this._removeChild(child); this._removeChild(child);
this._renderAdditionalElement(fromIdx, toIdx); this._renderExtraOnMove(fromIdx, toIdx);
this.onListChanged(); this.onListChanged();
} }
else if (!fromInRange && toInRange) { else if (!fromInRange && toInRange) {
this.onBeforeListChanged(); this.onBeforeListChanged();
const child = this._childCreator(value); const child = this._childCreator(value);
this._removeAdditionalElement(fromIdx, toIdx); this._removeElementOnMove(fromIdx, toIdx);
this._childInstances.splice(normalizedToIdx, 0, child); this._childInstances.splice(normalizedToIdx, 0, child);
insertAt(this._root, normalizedToIdx, mountView(child, this._mountArgs)); insertAt(this._root, normalizedToIdx, mountView(child, this._mountArgs));
this.onListChanged(); this.onListChanged();