fix(sideMenu): enable menu w/ different historyId back view

This commit is contained in:
Adam Bradley
2014-12-03 23:28:00 -06:00
parent 74cc98039b
commit 6a1c53301c
3 changed files with 65 additions and 5 deletions

View File

@@ -368,7 +368,12 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io
startX <= self.edgeThreshold ||
startX >= self.content.element.offsetWidth - self.edgeThreshold;
var menuEnabled = self.enableMenuWithBackViews() ? true : !$ionicHistory.backView();
var backView = $ionicHistory.backView();
var menuEnabled = enableMenuWithBackViews ? true : !backView;
if (!menuEnabled) {
var currentView = $ionicHistory.currentView() || {};
return backView.historyId !== currentView.historyId;
}
return ($scope.dragContent || self.isOpen()) &&
dragIsWithinBounds &&

View File

@@ -482,9 +482,12 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
* @description Returns the view that was before the current view in the history stack.
* If the user navigated from View A to View B, then View A would be the back view, and
* View B would be the current view.
* @returns {string} Returns the back view.
* @returns {object} Returns the back view.
*/
backView: function() {
backView: function(view) {
if (arguments.length) {
viewHistory.backView = view;
}
return viewHistory.backView;
},
@@ -507,9 +510,12 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
* A forward view would exist if the user navigated from View A to View B, then
* navigated back to View A. At this point then View B would be the forward view, and View
* A would be the current view.
* @returns {string} Returns the back view.
* @returns {object} Returns the forward view.
*/
forwardView: function() {
forwardView: function(view) {
if (arguments.length) {
viewHistory.forwardView = view;
}
return viewHistory.forwardView;
},

View File

@@ -170,6 +170,55 @@ describe('Ionic Angular Side Menu', function() {
expect(ctrl.isDraggableTarget(e)).toBe(true);
}));
it('should isDraggableTarget w/ enableMenuWithBackViews', inject(function($compile, $rootScope, $ionicHistory) {
var el = $compile('<ion-side-menus><ion-side-menu-content></ion-side-menu-content></ion-side-menus>')($rootScope.$new());
$rootScope.$apply();
var ctrl = el.controller('ionSideMenus');
var e = {
gesture: {
srcEvent: {
defaultPrevented: false
}
},
target: {
tagName: 'DIV',
dataset: {
preventScroll: false
}
}
};
ctrl.enableMenuWithBackViews(true);
expect(ctrl.isDraggableTarget(e)).toBe(true);
ctrl.enableMenuWithBackViews(false);
expect(ctrl.isDraggableTarget(e)).toBe(true);
ctrl.enableMenuWithBackViews(false);
$ionicHistory.currentView({historyId: 'root'});
$ionicHistory.backView({historyId: 'root'});
expect(ctrl.isDraggableTarget(e)).toBe(false);
ctrl.enableMenuWithBackViews(false);
$ionicHistory.currentView({historyId: 'root'});
$ionicHistory.backView(null);
expect(ctrl.isDraggableTarget(e)).toBe(true);
ctrl.enableMenuWithBackViews(true);
$ionicHistory.currentView({historyId: 'root'});
$ionicHistory.backView({historyId: 'root'});
expect(ctrl.isDraggableTarget(e)).toBe(true);
ctrl.enableMenuWithBackViews(false);
$ionicHistory.currentView({historyId: '003'});
$ionicHistory.backView({historyId: 'root'});
expect(ctrl.isDraggableTarget(e)).toBe(true);
}));
});
describe('Ionic Side Menu Content Directive', function () {