mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat(tabs): clicking tab item again navigates to tab's home
This commit is contained in:
7
js/ext/angular/src/directive/ionicTabBar.js
vendored
7
js/ext/angular/src/directive/ionicTabBar.js
vendored
@@ -13,7 +13,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
|
||||
$ionicViewService.disableRegisterByTagName('tabs');
|
||||
}])
|
||||
|
||||
.directive('tabs', [function() {
|
||||
.directive('tabs', ['$ionicViewService', function($ionicViewService) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
@@ -80,6 +80,11 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
|
||||
if(emitChange) {
|
||||
$scope.$emit('viewState.changeHistory', viewData);
|
||||
}
|
||||
} else if(emitChange) {
|
||||
var currentView = $ionicViewService.getCurrentView();
|
||||
if(currentView) {
|
||||
$ionicViewService.goToHistoryRoot(currentView.historyId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
23
js/ext/angular/src/service/ionicView.js
vendored
23
js/ext/angular/src/service/ionicView.js
vendored
@@ -78,7 +78,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
|
||||
}
|
||||
return null;
|
||||
};
|
||||
View.prototype.go = function(opts) {
|
||||
View.prototype.go = function() {
|
||||
|
||||
if(this.stateName) {
|
||||
return $state.go(this.stateName, this.stateParams);
|
||||
@@ -143,7 +143,12 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
|
||||
return rsp;
|
||||
}
|
||||
|
||||
if(backView && backView.stateId === currentStateId) {
|
||||
if(viewHistory.forcedNav) {
|
||||
// we've previously set exactly what to do
|
||||
ionic.Utils.extend(rsp, viewHistory.forcedNav);
|
||||
$rootScope.$viewHistory.forcedNav = null;
|
||||
|
||||
} else if(backView && backView.stateId === currentStateId) {
|
||||
// they went back one, set the old current view as a forward view
|
||||
rsp.viewId = backView.viewId;
|
||||
rsp.navAction = 'moveBack';
|
||||
@@ -311,6 +316,20 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
|
||||
return ionic.Utils.nextUid();
|
||||
},
|
||||
|
||||
goToHistoryRoot: function(historyId) {
|
||||
if(historyId) {
|
||||
var hist = $rootScope.$viewHistory.histories[ historyId ];
|
||||
if(hist && hist.stack.length) {
|
||||
$rootScope.$viewHistory.forcedNav = {
|
||||
viewId: hist.stack[0].viewId,
|
||||
navAction: 'moveBack',
|
||||
navDirection: 'back'
|
||||
};
|
||||
hist.stack[0].go();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_getView: function(viewId) {
|
||||
return (viewId ? $rootScope.$viewHistory.histories[ viewId ] : null );
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user