Skip to content

Commit e917cae

Browse files
committed
fix(scrolling): Prevent gestures from breaking native scrolling
1 parent 7bf1207 commit e917cae

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

js/angular/directive/sideMenuContent.js

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ function($timeout, $ionicGesture, $window) {
182182

183183
// add gesture handlers
184184
var gestureOpts = { stop_browser_behavior: false };
185+
if (ionic.DomUtil.getParentOrSelfWithClass($element[0],'overflow-scroll')) {
186+
gestureOpts.prevent_default_directions = ['left','right'];
187+
}
185188
var contentTapGesture = $ionicGesture.on('tap', onContentTap, $element, gestureOpts);
186189
var dragRightGesture = $ionicGesture.on('dragright', onDragX, $element, gestureOpts);
187190
var dragLeftGesture = $ionicGesture.on('dragleft', onDragX, $element, gestureOpts);

js/utils/gestures.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1160,16 +1160,19 @@
11601160
drag_lock_to_axis : false,
11611161
// drag lock only kicks in when distance > drag_lock_min_distance
11621162
// This way, locking occurs only when the distance has become large enough to reliably determine the direction
1163-
drag_lock_min_distance : 25
1163+
drag_lock_min_distance : 25,
1164+
// prevent default if the gesture is going the given direction
1165+
prevent_default_directions : []
11641166
},
11651167
triggered: false,
11661168
handler: function dragGesture(ev, inst) {
1167-
11681169
if (ev.srcEvent.type == 'touchstart' || ev.srcEvent.type == 'touchend') {
11691170
this.preventedFirstMove = false;
11701171

11711172
} else if (!this.preventedFirstMove && ev.srcEvent.type == 'touchmove') {
1172-
ev.srcEvent.preventDefault();
1173+
if (inst.options.prevent_default_directions.indexOf(ev.direction) != -1) {
1174+
ev.srcEvent.preventDefault();
1175+
}
11731176
this.preventedFirstMove = true;
11741177
}
11751178

js/views/listView.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,19 @@
394394
self.onRefreshOpening = opts.onRefreshOpening || function() {};
395395
self.onRefreshHolding = opts.onRefreshHolding || function() {};
396396

397+
var gestureOpts = {};
398+
// don't prevent native scrolling
399+
if (ionic.DomUtil.getParentOrSelfWithClass(self.el,'overflow-scroll')) {
400+
gestureOpts.prevent_default_directions = ['left','right'];
401+
}
402+
397403
window.ionic.onGesture('release', function(e) {
398404
self._handleEndDrag(e);
399-
}, self.el);
405+
}, self.el, gestureOpts);
400406

401407
window.ionic.onGesture('drag', function(e) {
402408
self._handleDrag(e);
403-
}, self.el);
409+
}, self.el, gestureOpts);
404410
// Start the drag states
405411
self._initDrag();
406412
},

test/unit/angular/directive/list.unit.js

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ describe('ionList directive', function() {
2525
expect(el.children().html()).toBe('<hello></hello>');
2626
});
2727

28+
it('should provide gesture prevent_default_directions if native scrolling', function() {
29+
spyOn(window.ionic,'onGesture');
30+
31+
var el = setup('', '<hello></hello>');
32+
flush();
33+
expect(window.ionic.onGesture).toHaveBeenCalled();
34+
args = window.ionic.onGesture.mostRecentCall.args;
35+
expect(args[3]).toEqual({});
36+
37+
var el = setup('class="overflow-scroll"', '<hello></hello>');
38+
flush();
39+
var gestureOpts = {prevent_default_directions: ['left','right']};
40+
args = window.ionic.onGesture.mostRecentCall.args;
41+
expect(args[3]).toEqual(gestureOpts);
42+
});
43+
2844
it('should give options to listView after init', function() {
2945
var options;
3046
spyOn(ionic.views, 'ListView').andCallFake(function(o) {

0 commit comments

Comments
 (0)