Skip to content

Commit

Permalink
feat(scroll): freeze scroll on ion-option-button swipe
Browse files Browse the repository at this point in the history
Closes #2950
  • Loading branch information
adamdbradley committed Feb 12, 2015
1 parent c0b0d78 commit 9a88c41
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 114 deletions.
25 changes: 15 additions & 10 deletions js/angular/controller/navViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
$element.data('$uiView', viewData);

var deregisterInstance = $ionicNavViewDelegate._registerInstance(self, $attrs.delegateHandle);
$scope.$on('$destroy', deregisterInstance);
$scope.$on('$destroy', function() {
deregisterInstance();

// ensure no scrolls have been left frozen
if (self.isSwipeFreeze) {
$ionicScrollDelegate.freezeAllScrolls(false);
}
});

$scope.$on('$ionicHistory.deselect', self.cacheCleanup);

Expand Down Expand Up @@ -176,6 +183,11 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
}

navSwipeAttr('');

// ensure no scrolls have been left frozen
if (self.isSwipeFreeze) {
$ionicScrollDelegate.freezeAllScrolls(false);
}
};


Expand Down Expand Up @@ -303,7 +315,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,

if (!windowWidth) windowWidth = window.innerWidth;

freezeScrolls(true);
self.isSwipeFreeze = $ionicScrollDelegate.freezeAllScrolls(true);

var registerData = {
direction: 'back'
Expand Down Expand Up @@ -387,7 +399,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,

windowWidth = viewTransition = dragPoints = null;

freezeScrolls(false);
self.isSwipeFreeze = $ionicScrollDelegate.freezeAllScrolls(false);
}

function getDragX(ev) {
Expand All @@ -409,13 +421,6 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
};


function freezeScrolls(freeze) {
forEach($ionicScrollDelegate._instances, function(instance) {
instance.freezeScroll(freeze);
});
}


function navSwipeAttr(val) {
ionic.DomUtil.cachedAttr($element, 'nav-swipe', val);
}
Expand Down
9 changes: 6 additions & 3 deletions js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ function($scope,
});
};

self.freezeScroll = function(shouldFreeze) {
if (arguments.length) scrollView.options.freeze = shouldFreeze;
return scrollView.options.freeze;
self.freezeScroll = scrollView.freeze;

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


Expand Down
13 changes: 7 additions & 6 deletions js/angular/directive/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ function($timeout) {
controller: '$ionicList',
compile: function($element, $attr) {
var listEl = jqLite('<div class="list">')
.append( $element.contents() )
.append($element.contents())
.addClass($attr.type);

$element.append(listEl);

return function($scope, $element, $attrs, ctrls) {
var listCtrl = ctrls[0];
var scrollCtrl = ctrls[1];

//Wait for child elements to render...
// Wait for child elements to render...
$timeout(init);

function init() {
Expand All @@ -111,9 +112,9 @@ function($timeout) {
onReorder: function(el, oldIndex, newIndex) {
var itemScope = jqLite(el).scope();
if (itemScope && itemScope.$onReorder) {
//Make sure onReorder is called in apply cycle,
//but also make sure it has no conflicts by doing
//$evalAsync
// Make sure onReorder is called in apply cycle,
// but also make sure it has no conflicts by doing
// $evalAsync
$timeout(function() {
itemScope.$onReorder(oldIndex, newIndex);
});
Expand All @@ -125,7 +126,7 @@ function($timeout) {
});

$scope.$on('$destroy', function() {
if(listView) {
if (listView) {
listView.deregister && listView.deregister();
listView = null;
}
Expand Down
10 changes: 9 additions & 1 deletion js/angular/service/scrollDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,18 @@ IonicModule
/**
* @ngdoc method
* @name $ionicScrollDelegate#freezeScroll
* @description Does not allow the scrollView to scroll in either x or y.
* @description Does not allow this scroll view to scroll either x or y.
* @param {boolean=} shouldFreeze Should this scroll view be prevented from scrolling or not.
* @returns {object} If the scroll view is being prevented from scrolling or not.
*/
'freezeScroll',
/**
* @ngdoc method
* @name $ionicScrollDelegate#freezeAllScrolls
* @description Does not allow any of the app's scroll views to scroll either x or y.
* @param {boolean=} shouldFreeze Should all app scrolls be prevented from scrolling or not.
*/
'freezeAllScrolls',
/**
* @ngdoc method
* @name $ionicScrollDelegate#getScrollView
Expand Down
Loading

0 comments on commit 9a88c41

Please sign in to comment.