Skip to content

Commit

Permalink
fix(sidemenu): prevent scroll during menu drag
Browse files Browse the repository at this point in the history
Closes #2808
  • Loading branch information
adamdbradley committed Feb 13, 2015
1 parent be09433 commit 51ed182
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function($scope,

self.freezeAllScrolls = function(shouldFreeze) {
for (var i = 0; i < $ionicScrollDelegate._instances.length; i++) {
$ionicScrollDelegate._instances[x].freezeScroll(shouldFreeze);
$ionicScrollDelegate._instances[i].freezeScroll(shouldFreeze);
}
};

Expand Down
21 changes: 20 additions & 1 deletion js/angular/controller/sideMenuController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ IonicModule
'$ionicPlatform',
'$ionicBody',
'$ionicHistory',
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory) {
'$ionicScrollDelegate',
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory, $ionicScrollDelegate) {
var self = this;
var rightShowing, leftShowing, isDragging;
var startX, lastX, offsetX, isAsideExposed;
Expand Down Expand Up @@ -148,8 +149,20 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
// add the CSS class "menu-open" if the percentage does not
// equal 0, otherwise remove the class from the body element
$ionicBody.enableClass((percentage !== 0), 'menu-open');

freezeAllScrolls(false);
};

function freezeAllScrolls(shouldFreeze) {
if (shouldFreeze && !self.isScrollFreeze) {
$ionicScrollDelegate.freezeAllScrolls(shouldFreeze);

} else if (!shouldFreeze && self.isScrollFreeze) {
$ionicScrollDelegate.freezeAllScrolls(false);
}
self.isScrollFreeze = shouldFreeze;
}

/**
* Open the menu the given pixel amount.
* @param {float} amount the pixel amount to open the menu. Positive value for left menu,
Expand Down Expand Up @@ -297,6 +310,8 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io

// End a drag with the given event
self._endDrag = function(e) {
freezeAllScrolls(false);

if (isAsideExposed) return;

if (isDragging) {
Expand Down Expand Up @@ -334,6 +349,7 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io

if (isDragging) {
self.openAmount(offsetX + (lastX - startX));
freezeAllScrolls(true);
}
};

Expand Down Expand Up @@ -415,6 +431,9 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
self.content.element = null;
self.content = null;
}

// ensure scrolls are unfrozen
freezeAllScrolls(false);
});

self.initialize({
Expand Down

0 comments on commit 51ed182

Please sign in to comment.