diff --git a/src/array-virtual-repeat-strategy.js b/src/array-virtual-repeat-strategy.js index dea49b0..4e2d3e7 100644 --- a/src/array-virtual-repeat-strategy.js +++ b/src/array-virtual-repeat-strategy.js @@ -239,6 +239,7 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy { _handleAddedSplices(repeat: VirtualRepeat, array: Array, 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; @@ -262,6 +263,11 @@ 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; @@ -269,5 +275,9 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy { } } repeat._adjustBufferHeights(); + + if (hasInsertedBeforeViewSlot) { + repeat._handleScroll(); + } } }