Skip to content

Commit

Permalink
fix(nav): back btn and bar hide/show
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adamdbradley committed Apr 6, 2015
1 parent 8fb9c08 commit 0936f78
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
28 changes: 23 additions & 5 deletions js/angular/controller/navBarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,24 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
navBarTransition.direction = 'back';
navBarTransition.run(step);
},
cancel: function(shouldAnimate, speed) {
cancel: function(shouldAnimate, speed, cancelData) {
navSwipeAttr(speed);
navBarAttr(leavingHeaderBar, 'active');
navBarAttr(enteringHeaderBar, 'cached');
navBarTransition.shouldAnimate = shouldAnimate;
navBarTransition.run(0);
self.activeTransition = navBarTransition = null;

var runApply;
if (cancelData.showBar !== self.showBar()) {
self.showBar(cancelData.showBar);
}
if (cancelData.showBackButton !== self.showBackButton()) {
self.showBackButton(cancelData.showBackButton);
}
if (runApply) {
$scope.$apply();
}
},
complete: function(shouldAnimate, speed) {
navSwipeAttr(speed);
Expand Down Expand Up @@ -373,10 +384,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
* to show.
*/
self.showBackButton = function(shouldShow) {
for (var x = 0; x < headerBars.length; x++) {
headerBars[x].controller().showNavBack(!!shouldShow);
if (arguments.length) {
for (var x = 0; x < headerBars.length; x++) {
headerBars[x].controller().showNavBack(!!shouldShow);
}
$scope.$isBackButtonShown = !!shouldShow;
}
$scope.$isBackButtonShown = !!shouldShow;
return $scope.$isBackButtonShown;
};

Expand All @@ -388,7 +401,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
*/
self.showActiveBackButton = function(shouldShow) {
var headerBar = getOnScreenHeaderBar();
headerBar && headerBar.controller().showBack(shouldShow);
if (headerBar) {
if (arguments.length) {
return headerBar.controller().showBack(shouldShow);
}
return headerBar.controller().showBack();
}
};


Expand Down
26 changes: 23 additions & 3 deletions js/angular/controller/navViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,25 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
*/
self.showBackButton = function(shouldShow) {
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
associatedNavBarCtrl && associatedNavBarCtrl.showActiveBackButton(shouldShow);
if (associatedNavBarCtrl) {
if (arguments.length) {
return associatedNavBarCtrl.showActiveBackButton(shouldShow);
}
return associatedNavBarCtrl.showActiveBackButton();
}
return true;
};


self.showBar = function(val) {
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
associatedNavBarCtrl && associatedNavBarCtrl.showBar(val);
if (associatedNavBarCtrl) {
if (arguments.length) {
return associatedNavBarCtrl.showBar(val);
}
return associatedNavBarCtrl.showBar();
}
return true;
};


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

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

dragPoints = [];

cancelData = {
showBar: self.showBar(),
showBackButton: self.showBackButton()
};

var switcher = $ionicViewSwitcher.create(self, registerData, backView, $ionicHistory.currentView(), true, false);
switcher.loadViewElements(registerData);
switcher.render(registerData);
Expand Down Expand Up @@ -399,16 +417,18 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
disableAnimation = (releaseSwipeCompletion < 0.03 || releaseSwipeCompletion > 0.97);

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

} else {
// cancel view transition on release
navSwipeAttr(disableAnimation ? '' : 'fast');
disableRenderStartViewId = null;
viewTransition.cancel(!disableAnimation);
associatedNavBarCtrl && associatedNavBarCtrl.activeTransition && associatedNavBarCtrl.activeTransition.cancel(!disableAnimation, 'fast');
associatedNavBarCtrl && associatedNavBarCtrl.activeTransition && associatedNavBarCtrl.activeTransition.cancel(!disableAnimation, 'fast', cancelData);
disableAnimation = null;
}

Expand Down

1 comment on commit 0936f78

@adamdbradley
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #3363 #3096

Please sign in to comment.