feat(tabs): clicking tab item again navigates to tab's home

This commit is contained in:
Adam Bradley
2014-02-04 23:01:40 -06:00
parent 1b4c77dc36
commit 24c382bd9b
2 changed files with 27 additions and 3 deletions

View File

@@ -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);
}
}
};

View File

@@ -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 );
},