diff --git a/js/angular/controller/navViewController.js b/js/angular/controller/navViewController.js index bedd568b1e5..4dbd7dad272 100644 --- a/js/angular/controller/navViewController.js +++ b/js/angular/controller/navViewController.js @@ -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); diff --git a/js/angular/directive/view.js b/js/angular/directive/view.js index a30f59aa8bb..ad03192052b 100644 --- a/js/angular/directive/view.js +++ b/js/angular/directive/view.js @@ -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 diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 6060a99bde0..a48a0f4cfe1 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -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([