diff --git a/js/angular/directive/menuClose.js b/js/angular/directive/menuClose.js index fe730b6ba4..e734607059 100644 --- a/js/angular/directive/menuClose.js +++ b/js/angular/directive/menuClose.js @@ -18,17 +18,17 @@ * ``` */ IonicModule -.directive('menuClose', ['$ionicViewSwitcher', function($ionicViewSwitcher) { +.directive('menuClose', ['$ionicViewSwitcher', '$ionicHistory', function($ionicViewSwitcher, $ionicHistory) { return { restrict: 'AC', link: function($scope, $element, $attr) { $element.bind('click', function() { var sideMenuCtrl = $element.inheritedData('$ionSideMenusController'); if (sideMenuCtrl) { - // lower priority than navAnimation which allows navTransition + // lower priority than navTransition which allows navTransition // to override this directive's nextTransition() call $ionicViewSwitcher.nextTransition('none'); - $ionicViewSwitcher.nextShowBack(false); + $ionicHistory.resetHistory(); sideMenuCtrl.close(); } }); diff --git a/js/angular/service/history.js b/js/angular/service/history.js index f34229db3b..7b7fa2dcf8 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -102,7 +102,7 @@ function($rootScope, $state, $location, $window) { var DIRECTION_NONE = 'none'; var stateChangeCounter = 0; - var lastStateId; + var lastStateId, setNextAsHistoryRoot; var viewHistory = { histories: { root: { historyId: 'root', parentHistoryId: null, stack: [], cursor: -1 } }, @@ -244,7 +244,7 @@ function($rootScope, $state, $location, $window) { action = null, direction = DIRECTION_NONE, historyId = hist.historyId, - tmp; + tmp, x; if (isAbstractView) { // abstract states should not register themselves in the history stack @@ -365,7 +365,7 @@ function($rootScope, $state, $location, $window) { tmp = getHistoryById(forwardView.historyId); if (tmp) { // the forward has a history - for (var x=tmp.stack.length - 1; x >= forwardView.index; x--) { + for (x = tmp.stack.length - 1; x >= forwardView.index; x--) { // starting from the end destroy all forwards in this history from this point tmp.stack[x].destroy(); tmp.stack.splice(x); @@ -420,6 +420,19 @@ function($rootScope, $state, $location, $window) { hist.stack.push(viewHistory.views[viewId]); } + if (setNextAsHistoryRoot) { + for (x = 0; x < hist.stack.length; x++) { + if (hist.stack[x].viewId === viewId) { + hist.stack[x].index = 0; + hist.stack[x].backViewId = hist.stack[x].forwardViewId = null; + } else { + delete viewHistory.views[hist.stack[x].viewId]; + } + } + hist.stack = [viewHistory.views[viewId]]; + setNextAsHistoryRoot = false; + } + setNavViews(viewId); hist.cursor = viewHistory.currentView.index; @@ -539,6 +552,10 @@ function($rootScope, $state, $location, $window) { if (currentView) { setNavViews(currentView.viewId); } + }, + + resetHistory: function() { + setNextAsHistoryRoot = true; } }; diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js index cd1c32de49..c1e8062ca5 100644 --- a/js/angular/service/viewSwitcher.js +++ b/js/angular/service/viewSwitcher.js @@ -29,7 +29,7 @@ function($timeout, $compile, $controller, $document, $ionicClickBlock, $ionicCon var VIEW_STATUS_STAGED = 'stage'; var transitionCounter = 0; - var nextTransition, nextDirection, nextShowBack; + var nextTransition, nextDirection; ionic.transition = ionic.transition || {}; ionic.transition.isActive = false; var isActiveTimer; @@ -73,7 +73,6 @@ function($timeout, $compile, $controller, $document, $ionicClickBlock, $ionicCon var transition = nextTransition || ionic.DomUtil.cachedAttr(enteringEle, 'view-transition') || state.viewTransition || $ionicConfig.views.transition() || 'none'; direction = nextDirection || ionic.DomUtil.cachedAttr(enteringEle, 'view-direction') || state.viewDirection || direction || 'none'; var shouldAnimate = (transition !== 'none' && direction !== 'none'); - showBack = (nextShowBack === true || nextShowBack === false ? nextShowBack : !!showBack); return { transition: transition, @@ -83,7 +82,7 @@ function($timeout, $compile, $controller, $document, $ionicClickBlock, $ionicCon stateId: enteringView.stateId, stateName: enteringView.stateName, stateParams: enteringView.stateParams, - showBack: showBack + showBack: !!showBack }; } @@ -274,7 +273,7 @@ function($timeout, $compile, $controller, $document, $ionicClickBlock, $ionicCon } // remove any references that could cause memory issues - nextTransition = nextDirection = nextShowBack = enteringView = enteringEle = leavingEle = null; + nextTransition = nextDirection = enteringView = enteringEle = leavingEle = null; } }, @@ -383,10 +382,6 @@ function($timeout, $compile, $controller, $document, $ionicClickBlock, $ionicCon nextDirection = val; }, - nextShowBack: function(val) { - nextShowBack = val; - }, - getTransitionData: getTransitionData, viewEleIsActive: function(viewEle, isActiveAttr) { diff --git a/test/unit/angular/service/viewSwitcher.unit.js b/test/unit/angular/service/viewSwitcher.unit.js index 726131349b..1fae6f2296 100644 --- a/test/unit/angular/service/viewSwitcher.unit.js +++ b/test/unit/angular/service/viewSwitcher.unit.js @@ -90,36 +90,6 @@ describe('Ionic View Switcher', function() { expect(d.showBack).toEqual(false); })); - it('should override showBack from view data w/ $ionicViewSwitcher.nextShowBack() setting', inject(function($ionicViewSwitcher) { - $ionicViewSwitcher.nextShowBack(true); - var d = $ionicViewSwitcher.getTransitionData(null, null, null, null, true); - expect(d.showBack).toEqual(true); - - $ionicViewSwitcher.nextShowBack(false); - var d = $ionicViewSwitcher.getTransitionData(null, null, null, null, true); - expect(d.showBack).toEqual(false); - - $ionicViewSwitcher.nextShowBack(true); - d = $ionicViewSwitcher.getTransitionData(null, null, null, null, false); - expect(d.showBack).toEqual(true); - - $ionicViewSwitcher.nextShowBack(false); - d = $ionicViewSwitcher.getTransitionData(null, null, null, null, false); - expect(d.showBack).toEqual(false); - - $ionicViewSwitcher.nextShowBack(true); - d = $ionicViewSwitcher.getTransitionData(null, null, null, null, null); - expect(d.showBack).toEqual(true); - - $ionicViewSwitcher.nextShowBack(false); - d = $ionicViewSwitcher.getTransitionData(null, null, null, null, null); - expect(d.showBack).toEqual(false); - - $ionicViewSwitcher.nextShowBack(null); - d = $ionicViewSwitcher.getTransitionData(null, null, null, null, true); - expect(d.showBack).toEqual(true); - })); - it('should get an empty entering element with an empty navViewElement', inject(function($ionicViewSwitcher) { var navViewElement = angular.element('
'); var switcher = $ionicViewSwitcher.create(null, navViewElement, {}, {});