Skip to content

Commit

Permalink
fix(scroll): cleanup native scroll listeners only if activated
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed Feb 13, 2015
1 parent be09433 commit df6dcb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions js/angular/controller/refresherController.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ IonicModule
ionic.on('touchmove', handleTouchmove, scrollChild);
ionic.on('touchend', handleTouchend, scrollChild);
ionic.on('scroll', handleScroll, scrollParent);
};


$scope.$on('$destroy', destroy);
// cleanup when done
$scope.$on('$destroy', destroy);
};

function destroy() {
ionic.off('dragdown', handleTouchmove, scrollChild);
ionic.off('dragend', handleTouchend, scrollChild);
ionic.off('touchmove', handleTouchmove, scrollChild);
ionic.off('touchend', handleTouchend, scrollChild);
ionic.off('scroll', handleScroll, scrollParent);
scrollParent = null;
scrollChild = null;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/angular/controller/refreshController.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ describe('$ionicRefresh Controller', function() {
ctrl.getRefresherDomMethods().hide();
expect(refresher.classList.contains('invisible')).toBe(true);
});

it('should cleanup when done', function() {
setup();

expect(ctrl.__getScrollChild()).not.toBe(null);
expect(ctrl.__getScrollParent()).not.toBe(null);

scope.$broadcast('$destroy');

expect(ctrl.__getScrollChild()).toBe(null);
expect(ctrl.__getScrollParent()).toBe(null);
});
});

0 comments on commit df6dcb9

Please sign in to comment.