feat(swipeBack): disable swipe back per view

Closes #3470
This commit is contained in:
Adam Bradley
2015-04-16 14:54:39 -05:00
parent 38c187ea25
commit c602cde87b
3 changed files with 19 additions and 3 deletions

View File

@@ -343,7 +343,9 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
backView = $ionicHistory.backView();
if (!backView || backView.historyId !== $ionicHistory.currentView().historyId) return;
var currentView = $ionicHistory.currentView();
if (!backView || backView.historyId !== currentView.historyId || currentView.canSwipeBack === false) return;
if (!windowWidth) windowWidth = window.innerWidth;
@@ -360,7 +362,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
showBackButton: self.showBackButton()
};
var switcher = $ionicViewSwitcher.create(self, registerData, backView, $ionicHistory.currentView(), true, false);
var switcher = $ionicViewSwitcher.create(self, registerData, backView, currentView, true, false);
switcher.loadViewElements(registerData);
switcher.render(registerData);

View File

@@ -97,6 +97,9 @@
* @param {boolean=} cache-view If this view should be allowed to be cached or not.
* Please see the _Caching_ section in {@link ionic.directive:ionNavView} for
* more info. Default `true`
* @param {boolean=} can-swipe-back If this view should be allowed to use the swipe to go back gesture or not.
* This does not enable the swipe to go back feature if it is not available for the platform it's running
* from, or there isn't a previous view. Default `true`
* @param {boolean=} hide-back-button Whether to hide the back button on the parent
* {@link ionic.directive:ionNavBar} by default.
* @param {boolean=} hide-nav-bar Whether to hide the parent

View File

@@ -359,7 +359,8 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
stateId: currentStateId,
stateName: this.currentStateName(),
stateParams: getCurrentStateParams(),
url: url
url: url,
canSwipeBack: canSwipeBack(ele, viewLocals)
});
// add the new view to this history's stack
@@ -717,6 +718,16 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
return ele && ele.length && /ion-side-menus|ion-tabs/i.test(ele[0].tagName);
}
function canSwipeBack(ele, viewLocals) {
if (viewLocals && viewLocals.$$state && viewLocals.$$state.self.canSwipeBack === false) {
return false;
}
if (ele && ele.attr('can-swipe-back') === 'false') {
return false;
}
return true;
}
}])
.run([