Skip to content

Commit

Permalink
fix aurelia#87: Adding items on top when scrolled down is not working…
Browse files Browse the repository at this point in the history
… correctly

After scrolling down inserting items at the top doesn't work as
expected, as it's only making the top buffer bigger. By triggering the
scrolling mechanism, the appropriate items are rendered.
  • Loading branch information
paulclijsters committed Dec 8, 2016
1 parent cc34dc6 commit 65b6e2e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/array-virtual-repeat-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy {
_handleAddedSplices(repeat: VirtualRepeat, array: Array<any>, splices: any): void {
let arrayLength = array.length;
let viewSlot = repeat.viewSlot;
let hasInsertedBeforeViewSlot = false;
for (let i = 0, ii = splices.length; i < ii; ++i) {
let splice = splices[i];
let addIndex = splice.index;
Expand All @@ -262,12 +263,21 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy {
}
} else if (this._isIndexBeforeViewSlot(repeat, viewSlot, addIndex)) {
repeat._topBufferHeight = repeat._topBufferHeight + repeat.itemHeight;
// As we're adding an item before the view slots, this can cause the buffer to run out of rendered items.
// By triggering the scrolling mechanism (after setting the previousFirst & lastRebind) the appropriate items are rendered.
hasInsertedBeforeViewSlot = true;
repeat._previousFirst = repeat._previousFirst + 1;
repeat._lastRebind = repeat._lastRebind + 1;
} else if (this._isIndexAfterViewSlot(repeat, viewSlot, addIndex)) {
repeat._bottomBufferHeight = repeat._bottomBufferHeight + repeat.itemHeight;
repeat.isLastIndex = false;
}
}
}
repeat._adjustBufferHeights();

if (hasInsertedBeforeViewSlot) {
repeat._handleScroll();
}
}
}

0 comments on commit 65b6e2e

Please sign in to comment.