Skip to content

Commit

Permalink
fix(refresher): PTR doesn't break after scrolling. Fixes #4753
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Dec 17, 2015
1 parent f11b6a8 commit 3efb33d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions js/angular/controller/refresherController.js
Expand Up @@ -49,12 +49,12 @@ IonicModule
}

function handleTouchend() {
// reset Y
startY = null;
// if this wasn't an overscroll, get out immediately
if (!canOverscroll && !isDragging) {
return;
}
// reset Y
startY = null;
// the user has overscrolled but went back to native scrolling
if (!isDragging) {
dragOffset = 0;
Expand Down Expand Up @@ -104,6 +104,8 @@ IonicModule
// if we've dragged up and back down in to native scroll territory
if (deltaY - dragOffset <= 0 || scrollParent.scrollTop !== 0) {

console.log('NOT PULLING', deltaY, dragOffset, scrollParent.scrollTop);

if (isOverscrolling) {
isOverscrolling = false;
setScrollLock(false);
Expand All @@ -120,6 +122,7 @@ IonicModule
return;

} else if (deltaY > 0 && scrollParent.scrollTop === 0 && !isOverscrolling) {
console.log('PULLING', deltaY, dragOffset, scrollParent.scrollTop, isOverscrolling);
// starting overscroll, but drag started below scrollTop 0, so we need to offset the position
dragOffset = deltaY;
}
Expand Down
13 changes: 10 additions & 3 deletions test/unit/angular/controller/refreshController.unit.js
Expand Up @@ -43,13 +43,17 @@ describe('$ionicRefresh Controller', function() {
}).toThrow();
});

it('should oversroll using CSS transforms', function() {
it('should overscroll using CSS transforms', function() {
setup();

function getTy(el) {
return parseInt(el.style[ionic.CSS.TRANSFORM].replace('translateY(', ''));
}

ctrl.__handleTouchmove(evt(0));
ctrl.__handleTouchmove(evt(10));
ctrl.__handleTouchmove(evt(20));
expect(ctrl.__getScrollChild().style[ionic.CSS.TRANSFORM]).toBe('translateY(3px)');
expect(getTy(ctrl.__getScrollChild())).toBe(3);
expect(ctrl.__getScrollChild().classList.contains('overscroll')).toBe(true);
expect(refresher.classList.contains('invisible')).toBe(false);
});
Expand All @@ -70,6 +74,9 @@ describe('$ionicRefresh Controller', function() {
});

it('should activate and deactivate when dragging past activation threshold', function() {
function getTy(el) {
return parseInt(el.style[ionic.CSS.TRANSFORM].replace('translateY(', ''));
}
setup();
var domMethods = ctrl.getRefresherDomMethods();
spyOn(domMethods, 'activate');
Expand All @@ -78,7 +85,7 @@ describe('$ionicRefresh Controller', function() {
ctrl.__handleTouchmove(evt(0));
ctrl.__handleTouchmove(evt(10));
ctrl.__handleTouchmove(evt(300));
expect(ctrl.__getScrollChild().style[ionic.CSS.TRANSFORM]).toBe('translateY(96px)');
expect(getTy(ctrl.__getScrollChild())).toBe(96);
expect(ctrl.__getScrollChild().classList.contains('overscroll')).toBe(true);
expect(refresher.classList.contains('invisible')).toBe(false);
expect(refresher.classList.contains('active')).toBe(true);
Expand Down

0 comments on commit 3efb33d

Please sign in to comment.