fix(menuClose): add resetHistory() to menuClose

This commit is contained in:
Adam Bradley
2014-11-12 22:22:39 -06:00
parent 6ea73e6f82
commit 49aaed7e7b
4 changed files with 26 additions and 44 deletions

View File

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

View File

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

View File

@@ -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) {

View File

@@ -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('<div class="view-container">');
var switcher = $ionicViewSwitcher.create(null, navViewElement, {}, {});