Skip to content

Commit 0936f78

Browse files
committed
fix(nav): back btn and bar hide/show
Fixed navbar `showBackButton()` and `showBar()` methods to not set values to false if they were not passed an argument. Also, when swipe to go back is canceled, then correctly reset bar and back button values prior to the swipe to go back setting. Closes
1 parent 8fb9c08 commit 0936f78

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

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

+23-5
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,24 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
272272
navBarTransition.direction = 'back';
273273
navBarTransition.run(step);
274274
},
275-
cancel: function(shouldAnimate, speed) {
275+
cancel: function(shouldAnimate, speed, cancelData) {
276276
navSwipeAttr(speed);
277277
navBarAttr(leavingHeaderBar, 'active');
278278
navBarAttr(enteringHeaderBar, 'cached');
279279
navBarTransition.shouldAnimate = shouldAnimate;
280280
navBarTransition.run(0);
281281
self.activeTransition = navBarTransition = null;
282+
283+
var runApply;
284+
if (cancelData.showBar !== self.showBar()) {
285+
self.showBar(cancelData.showBar);
286+
}
287+
if (cancelData.showBackButton !== self.showBackButton()) {
288+
self.showBackButton(cancelData.showBackButton);
289+
}
290+
if (runApply) {
291+
$scope.$apply();
292+
}
282293
},
283294
complete: function(shouldAnimate, speed) {
284295
navSwipeAttr(speed);
@@ -373,10 +384,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
373384
* to show.
374385
*/
375386
self.showBackButton = function(shouldShow) {
376-
for (var x = 0; x < headerBars.length; x++) {
377-
headerBars[x].controller().showNavBack(!!shouldShow);
387+
if (arguments.length) {
388+
for (var x = 0; x < headerBars.length; x++) {
389+
headerBars[x].controller().showNavBack(!!shouldShow);
390+
}
391+
$scope.$isBackButtonShown = !!shouldShow;
378392
}
379-
$scope.$isBackButtonShown = !!shouldShow;
380393
return $scope.$isBackButtonShown;
381394
};
382395

@@ -388,7 +401,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
388401
*/
389402
self.showActiveBackButton = function(shouldShow) {
390403
var headerBar = getOnScreenHeaderBar();
391-
headerBar && headerBar.controller().showBack(shouldShow);
404+
if (headerBar) {
405+
if (arguments.length) {
406+
return headerBar.controller().showBack(shouldShow);
407+
}
408+
return headerBar.controller().showBack();
409+
}
392410
};
393411

394412

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

+23-3
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,25 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
291291
*/
292292
self.showBackButton = function(shouldShow) {
293293
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
294-
associatedNavBarCtrl && associatedNavBarCtrl.showActiveBackButton(shouldShow);
294+
if (associatedNavBarCtrl) {
295+
if (arguments.length) {
296+
return associatedNavBarCtrl.showActiveBackButton(shouldShow);
297+
}
298+
return associatedNavBarCtrl.showActiveBackButton();
299+
}
300+
return true;
295301
};
296302

297303

298304
self.showBar = function(val) {
299305
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
300-
associatedNavBarCtrl && associatedNavBarCtrl.showBar(val);
306+
if (associatedNavBarCtrl) {
307+
if (arguments.length) {
308+
return associatedNavBarCtrl.showBar(val);
309+
}
310+
return associatedNavBarCtrl.showBar();
311+
}
312+
return true;
301313
};
302314

303315

@@ -322,6 +334,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
322334
var viewTransition, associatedNavBarCtrl, backView;
323335
var deregDragStart, deregDrag, deregRelease;
324336
var windowWidth, startDragX, dragPoints;
337+
var cancelData = {};
325338

326339
function onDragStart(ev) {
327340
if (!isPrimary) return;
@@ -343,6 +356,11 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
343356

344357
dragPoints = [];
345358

359+
cancelData = {
360+
showBar: self.showBar(),
361+
showBackButton: self.showBackButton()
362+
};
363+
346364
var switcher = $ionicViewSwitcher.create(self, registerData, backView, $ionicHistory.currentView(), true, false);
347365
switcher.loadViewElements(registerData);
348366
switcher.render(registerData);
@@ -399,16 +417,18 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
399417
disableAnimation = (releaseSwipeCompletion < 0.03 || releaseSwipeCompletion > 0.97);
400418

401419
if (isSwipingRight && (releaseSwipeCompletion > 0.5 || velocity > 0.1)) {
420+
// complete view transition on release
402421
var speed = (velocity > 0.5 || velocity < 0.05 || releaseX > windowWidth - 45) ? 'fast' : 'slow';
403422
navSwipeAttr(disableAnimation ? '' : speed);
404423
backView.go();
405424
associatedNavBarCtrl && associatedNavBarCtrl.activeTransition && associatedNavBarCtrl.activeTransition.complete(!disableAnimation, speed);
406425

407426
} else {
427+
// cancel view transition on release
408428
navSwipeAttr(disableAnimation ? '' : 'fast');
409429
disableRenderStartViewId = null;
410430
viewTransition.cancel(!disableAnimation);
411-
associatedNavBarCtrl && associatedNavBarCtrl.activeTransition && associatedNavBarCtrl.activeTransition.cancel(!disableAnimation, 'fast');
431+
associatedNavBarCtrl && associatedNavBarCtrl.activeTransition && associatedNavBarCtrl.activeTransition.cancel(!disableAnimation, 'fast', cancelData);
412432
disableAnimation = null;
413433
}
414434

0 commit comments

Comments
 (0)