Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(virtualRepeat): Do not scroll past bottom Fixes #6279 Might also fix
Browse files Browse the repository at this point in the history
 #4169

  Closes #6990
  • Loading branch information
kseamon authored and ThomasBurleson committed Feb 4, 2016
1 parent b683667 commit 9a36112
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/virtualRepeat/virtual-repeater.js
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
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

0 comments on commit 9a36112

Please sign in to comment.