Skip to content

Commit 51ed182

Browse files
committed
fix(sidemenu): prevent scroll during menu drag
Closes #2808
1 parent be09433 commit 51ed182

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Diff for: js/angular/controller/scrollController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function($scope,
162162

163163
self.freezeAllScrolls = function(shouldFreeze) {
164164
for (var i = 0; i < $ionicScrollDelegate._instances.length; i++) {
165-
$ionicScrollDelegate._instances[x].freezeScroll(shouldFreeze);
165+
$ionicScrollDelegate._instances[i].freezeScroll(shouldFreeze);
166166
}
167167
};
168168

Diff for: js/angular/controller/sideMenuController.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ IonicModule
66
'$ionicPlatform',
77
'$ionicBody',
88
'$ionicHistory',
9-
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory) {
9+
'$ionicScrollDelegate',
10+
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory, $ionicScrollDelegate) {
1011
var self = this;
1112
var rightShowing, leftShowing, isDragging;
1213
var startX, lastX, offsetX, isAsideExposed;
@@ -148,8 +149,20 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
148149
// add the CSS class "menu-open" if the percentage does not
149150
// equal 0, otherwise remove the class from the body element
150151
$ionicBody.enableClass((percentage !== 0), 'menu-open');
152+
153+
freezeAllScrolls(false);
151154
};
152155

156+
function freezeAllScrolls(shouldFreeze) {
157+
if (shouldFreeze && !self.isScrollFreeze) {
158+
$ionicScrollDelegate.freezeAllScrolls(shouldFreeze);
159+
160+
} else if (!shouldFreeze && self.isScrollFreeze) {
161+
$ionicScrollDelegate.freezeAllScrolls(false);
162+
}
163+
self.isScrollFreeze = shouldFreeze;
164+
}
165+
153166
/**
154167
* Open the menu the given pixel amount.
155168
* @param {float} amount the pixel amount to open the menu. Positive value for left menu,
@@ -297,6 +310,8 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
297310

298311
// End a drag with the given event
299312
self._endDrag = function(e) {
313+
freezeAllScrolls(false);
314+
300315
if (isAsideExposed) return;
301316

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

335350
if (isDragging) {
336351
self.openAmount(offsetX + (lastX - startX));
352+
freezeAllScrolls(true);
337353
}
338354
};
339355

@@ -415,6 +431,9 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
415431
self.content.element = null;
416432
self.content = null;
417433
}
434+
435+
// ensure scrolls are unfrozen
436+
freezeAllScrolls(false);
418437
});
419438

420439
self.initialize({

0 commit comments

Comments
 (0)