Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix(virtualRepeat): Do not scroll past bottom #6990

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/components/virtualRepeat/virtual-repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,23 @@ VirtualRepeatContainerController.prototype.resetScroll = function() {

VirtualRepeatContainerController.prototype.handleScroll_ = function() {
var offset = this.isHorizontal() ? this.scroller.scrollLeft : this.scroller.scrollTop;
if (offset === this.scrollOffset) return;
if (offset === this.scrollOffset || offset > this.scrollSize - this.size) return;

var itemSize = this.repeater.getItemSize();
if (!itemSize) return;

var numItems = Math.max(0, Math.floor(offset / itemSize) - NUM_EXTRA);

var transform = this.isHorizontal() ? 'translateX(' : 'translateY(';
transform += (numItems * itemSize) + 'px)';
var transform = (this.isHorizontal() ? 'translateX(' : 'translateY(') +
(numItems * itemSize) + 'px)';

this.scrollOffset = offset;
this.offsetter.style.webkitTransform = transform;
this.offsetter.style.transform = transform;

if (this.bindTopIndex) {
var topIndex = Math.floor(offset / itemSize);
if (topIndex !== this.topIndex && topIndex < this.repeater.itemsLength) {
if (topIndex !== this.topIndex && topIndex < this.repeater.getItemCount()) {
this.topIndex = topIndex;
this.bindTopIndex.assign(this.$scope, topIndex);
if (!this.$rootScope.$$phase) this.$scope.$digest();
Expand Down Expand Up @@ -627,6 +627,15 @@ VirtualRepeatController.prototype.getItemSize = function() {
};


/**
* Called by the container. Returns the size of a single repeated item.
* @return {?number} Size of a repeated item.
*/
VirtualRepeatController.prototype.getItemCount = function() {
return this.itemsLength;
};


/**
* Updates the order and visible offset of repeated blocks in response to scrolling
* or items updates.
Expand Down
15 changes: 15 additions & 0 deletions src/components/virtualRepeat/virtual-repeater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,21 @@ describe('<md-virtual-repeat>', function() {
expect(offsetter.children().length).toBe(3);
}));

it('should not scroll past the bottom', function() {
scope.items = createItems(101);
createRepeater();

scroller[0].scrollTop = ITEM_SIZE * 91;
scroller.triggerHandler('scroll');

expect(getTransform(offsetter)).toBe('translateY(880px)');

scroller[0].scrollTop++;
scroller.triggerHandler('scroll');

expect(getTransform(offsetter)).toBe('translateY(880px)');
});

/**
* Facade to access transform properly even when jQuery is used;
* since jQuery's css function is obtaining the computed style (not wanted)
Expand Down