Skip to content

Commit c602cde

Browse files
committed
feat(swipeBack): disable swipe back per view
Closes #3470
1 parent 38c187e commit c602cde

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Diff for: js/angular/controller/navViewController.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
343343

344344
backView = $ionicHistory.backView();
345345

346-
if (!backView || backView.historyId !== $ionicHistory.currentView().historyId) return;
346+
var currentView = $ionicHistory.currentView();
347+
348+
if (!backView || backView.historyId !== currentView.historyId || currentView.canSwipeBack === false) return;
347349

348350
if (!windowWidth) windowWidth = window.innerWidth;
349351

@@ -360,7 +362,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
360362
showBackButton: self.showBackButton()
361363
};
362364

363-
var switcher = $ionicViewSwitcher.create(self, registerData, backView, $ionicHistory.currentView(), true, false);
365+
var switcher = $ionicViewSwitcher.create(self, registerData, backView, currentView, true, false);
364366
switcher.loadViewElements(registerData);
365367
switcher.render(registerData);
366368

Diff for: js/angular/directive/view.js

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

Diff for: js/angular/service/history.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
359359
stateId: currentStateId,
360360
stateName: this.currentStateName(),
361361
stateParams: getCurrentStateParams(),
362-
url: url
362+
url: url,
363+
canSwipeBack: canSwipeBack(ele, viewLocals)
363364
});
364365

365366
// add the new view to this history's stack
@@ -717,6 +718,16 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
717718
return ele && ele.length && /ion-side-menus|ion-tabs/i.test(ele[0].tagName);
718719
}
719720

721+
function canSwipeBack(ele, viewLocals) {
722+
if (viewLocals && viewLocals.$$state && viewLocals.$$state.self.canSwipeBack === false) {
723+
return false;
724+
}
725+
if (ele && ele.attr('can-swipe-back') === 'false') {
726+
return false;
727+
}
728+
return true;
729+
}
730+
720731
}])
721732

722733
.run([

0 commit comments

Comments
 (0)