mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(backButton): separate show/enable logic
Previously the showBack property was setting if the back button should or should not be enabled, and it was also used if the back button should be hidden or not for the view. Changed it so there are now two concepts, where showBack is visual only, and enableBack determines if it should show according to $ionicHistory and navigation info.
This commit is contained in:
24
js/angular/controller/headerBarController.js
vendored
24
js/angular/controller/headerBarController.js
vendored
@@ -21,7 +21,8 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) {
|
||||
var titleLeft = 0;
|
||||
var titleRight = 0;
|
||||
var titleCss = '';
|
||||
var isBackShown;
|
||||
var isBackEnabled = false;
|
||||
var isBackShown = false;
|
||||
var titleTextWidth = 0;
|
||||
|
||||
|
||||
@@ -40,13 +41,25 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) {
|
||||
};
|
||||
|
||||
|
||||
self.enableBack = function(shouldEnable) {
|
||||
// whether or not the back button show be visible, according
|
||||
// to the navigation and history
|
||||
if (arguments.length && shouldEnable !== isBackEnabled) {
|
||||
var backBtnEle = getEle(BACK_BUTTON);
|
||||
backBtnEle && backBtnEle.classList[ shouldEnable ? 'remove' : 'add' ](HIDE);
|
||||
isBackEnabled = shouldEnable;
|
||||
}
|
||||
return isBackEnabled;
|
||||
};
|
||||
|
||||
|
||||
self.showBack = function(shouldShow) {
|
||||
// different from enableBack() because this will always have the back
|
||||
// visually hidden if false, even if the history says it should show
|
||||
if (arguments.length && shouldShow !== isBackShown) {
|
||||
var backBtnEle = getEle(BACK_BUTTON);
|
||||
if (backBtnEle) {
|
||||
backBtnEle.classList[ shouldShow ? 'remove' : 'add' ](HIDE);
|
||||
isBackShown = shouldShow;
|
||||
}
|
||||
if (backBtnEle) backBtnEle.style.display = (shouldShow ? '' : 'none');
|
||||
isBackShown = shouldShow;
|
||||
}
|
||||
return isBackShown;
|
||||
};
|
||||
@@ -109,6 +122,7 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) {
|
||||
defaultTitleEle.classList.remove(HIDE);
|
||||
}
|
||||
}
|
||||
self.showBack(true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
18
js/angular/controller/navBarController.js
vendored
18
js/angular/controller/navBarController.js
vendored
@@ -77,6 +77,9 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
|
||||
|
||||
var headerBarInstance = {
|
||||
isActive: isActive,
|
||||
enableBack: function(shouldEnable) {
|
||||
headerBarCtrl.enableBack(shouldEnable);
|
||||
},
|
||||
showBack: function(shouldShow) {
|
||||
headerBarCtrl.showBack(shouldShow);
|
||||
},
|
||||
@@ -209,6 +212,7 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
|
||||
var leavingHeaderBar = self.isInitialized ? getOnScreenHeaderBar() : null;
|
||||
|
||||
// update if the entering header should show the back button or not
|
||||
self.enableBackButton(viewData.enableBack, enteringHeaderBar);
|
||||
self.showBackButton(viewData.showBack, enteringHeaderBar);
|
||||
|
||||
// update the entering header bar's title
|
||||
@@ -326,11 +330,17 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
|
||||
};
|
||||
|
||||
|
||||
self.showBackButton = function(show, headerBar) {
|
||||
self.enableBackButton = function(shouldEnable, headerBar) {
|
||||
headerBar = headerBar || getOnScreenHeaderBar();
|
||||
headerBar && headerBar.showBack(show);
|
||||
$scope.$isBackButtonShown = !!show;
|
||||
return !!show;
|
||||
headerBar && headerBar.enableBack(shouldEnable);
|
||||
};
|
||||
|
||||
|
||||
self.showBackButton = function(shouldShow, headerBar) {
|
||||
headerBar = headerBar || getOnScreenHeaderBar();
|
||||
headerBar && headerBar.showBack(shouldShow);
|
||||
$scope.$isBackButtonShown = !!shouldShow;
|
||||
return !!shouldShow;
|
||||
};
|
||||
|
||||
|
||||
|
||||
12
js/angular/controller/navViewController.js
vendored
12
js/angular/controller/navViewController.js
vendored
@@ -89,7 +89,7 @@ function($scope, $element, $attrs, $ionicNavBarDelegate, $ionicHistory, $ionicVi
|
||||
// the view is now compiled, in the dom and linked, now lets transition the views.
|
||||
// this uses a callback incase THIS nav-view has a nested nav-view, and after the NESTED
|
||||
// nav-view links, the NESTED nav-view would update which direction THIS nav-view should use
|
||||
switcher.transition(self.direction(), registerData.showBack);
|
||||
switcher.transition(self.direction(), registerData.enableBack);
|
||||
});
|
||||
|
||||
};
|
||||
@@ -111,9 +111,15 @@ function($scope, $element, $attrs, $ionicNavBarDelegate, $ionicHistory, $ionicVi
|
||||
};
|
||||
|
||||
|
||||
self.showBackButton = function(val) {
|
||||
self.enableBackButton = function(shouldEnable) {
|
||||
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.showBackButton(val);
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.enableBackButton(shouldEnable);
|
||||
};
|
||||
|
||||
|
||||
self.showBackButton = function(shouldShow) {
|
||||
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.showBackButton(shouldShow);
|
||||
};
|
||||
|
||||
|
||||
|
||||
5
js/angular/controller/viewController.js
vendored
5
js/angular/controller/viewController.js
vendored
@@ -54,7 +54,8 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
|
||||
transition: transData.transition,
|
||||
transitionId: transData.transitionId,
|
||||
shouldAnimate: transData.shouldAnimate,
|
||||
showBack: transData.showBack && !attrTrue('hideBackButton'),
|
||||
enableBack: transData.enableBack,
|
||||
showBack: !attrTrue('hideBackButton'),
|
||||
buttons: buttons,
|
||||
navBarDelegate: navBarDelegateHandle || null,
|
||||
showNavBar: !attrTrue('hideNavBar'),
|
||||
@@ -111,7 +112,7 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
|
||||
|
||||
|
||||
function attrTrue(key) {
|
||||
return $attrs[key] == 'true' || $attrs[key] === '';
|
||||
return !!$scope.$eval($attrs[key]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user