Skip to content

Commit

Permalink
feat(swipeBack): disable swipe back per view
Browse files Browse the repository at this point in the history
Closes #3470
  • Loading branch information
adamdbradley committed Apr 16, 2015
1 parent 38c187e commit c602cde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions js/angular/controller/navViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions js/angular/directive/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion js/angular/service/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit c602cde

Please sign in to comment.