From 1395513aa45d9d236f59c2b3594e611e9a5ed293 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 13 Nov 2014 09:00:07 -0600 Subject: [PATCH] fix(hideNavBar): send data in $ionicView.beforeEnter --- js/angular/controller/navBarController.js | 11 ++++++--- js/angular/controller/viewController.js | 1 + test/unit/angular/directive/navBar.unit.js | 27 ++++++++++++++++++++++ test/unit/angular/directive/view.unit.js | 19 +++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index 38f877e3b8..9858c28594 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -195,7 +195,7 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io self.update = function(viewData) { - var showNavBar = !viewData.hasHeaderBar; + var showNavBar = !viewData.hasHeaderBar && viewData.showNavBar; viewData.transition = $ionicConfig.navBar.transition(); if (!showNavBar) { @@ -212,6 +212,8 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io // update the entering header bar's title self.title(viewData.title, enteringHeaderBar); + self.showBar(showNavBar); + // update the buttons, depending if the view has their own or not if (viewData.buttons) { forEach(BUTTON_TYPES, function(buttonType) { @@ -293,8 +295,11 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io self.showBar = function(shouldShow) { - self.visibleBar(shouldShow); - $scope.$parent.$hasHeader = !!shouldShow; + if (arguments.length) { + self.visibleBar(shouldShow); + $scope.$parent.$hasHeader = !!shouldShow; + } + return !!$scope.$parent.$hasHeader; }; diff --git a/js/angular/controller/viewController.js b/js/angular/controller/viewController.js index db505c950f..6272953b0b 100644 --- a/js/angular/controller/viewController.js +++ b/js/angular/controller/viewController.js @@ -71,6 +71,7 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher) showBack: transData.showBack && !$attrs.hideBackButton, buttons: buttons, navBarDelegate: navBarDelegateHandle || null, + showNavBar: !($attrs.hideNavBar === "true" || $attrs.hideNavBar === ""), hasHeaderBar: !!hasViewHeaderBar }); } diff --git a/test/unit/angular/directive/navBar.unit.js b/test/unit/angular/directive/navBar.unit.js index fd12609c59..e2e087574e 100644 --- a/test/unit/angular/directive/navBar.unit.js +++ b/test/unit/angular/directive/navBar.unit.js @@ -57,6 +57,33 @@ describe('ionNavBar', function() { expect(ctrl.title()).toBe('foo'); }); + it('should showBar=true with update data showNavBar=true', function() { + setup(); + ctrl.update({ + showNavBar: true, + hasHeaderBar: false + }); + expect(ctrl.showBar()).toBe(true); + }); + + it('should showBar=false with update data showNavBar=false', function() { + setup(); + ctrl.update({ + showNavBar: false, + hasHeaderBar: false + }); + expect(ctrl.showBar()).toBe(false); + }); + + it('should showBar=false with update data showNavBar=true and hasHeaderBar=true', function() { + setup(); + ctrl.update({ + showNavBar: false, + hasHeaderBar: true + }); + expect(ctrl.showBar()).toBe(false); + }); + }); describe('directive', function() { diff --git a/test/unit/angular/directive/view.unit.js b/test/unit/angular/directive/view.unit.js index 26a3b49607..1cddf5f476 100644 --- a/test/unit/angular/directive/view.unit.js +++ b/test/unit/angular/directive/view.unit.js @@ -45,6 +45,24 @@ describe('ionView directive', function() { expect(el.html()).toBe('some html'); }); + it('should call ionNavViewController.beforeEnter with showNavBar=false and hide-nav-bar=true attr', inject(function($rootScope) { + var el = setup('hide-nav-bar="true"'); + $rootScope.$broadcast('$ionicView.beforeEnter', {}); + expect( beforeEnterData.showNavBar ).toBe(false); + })); + + it('should call ionNavViewController.beforeEnter with showNavBar=false and hide-nav-bar="" attr', inject(function($rootScope) { + var el = setup('hide-nav-bar'); + $rootScope.$broadcast('$ionicView.beforeEnter', {}); + expect( beforeEnterData.showNavBar ).toBe(false); + })); + + it('should call ionNavViewController.beforeEnter with showNavBar=true and hide-nav-bar=false attr', inject(function($rootScope) { + var el = setup('hide-nav-bar="false"'); + $rootScope.$broadcast('$ionicView.beforeEnter', {}); + expect( beforeEnterData.showNavBar ).toBe(true); + })); + it('should call ionNavViewController.beforeEnter with title attr', inject(function($rootScope) { var el = setup('title="my title"'); $rootScope.$broadcast('$ionicView.beforeEnter', { @@ -54,6 +72,7 @@ describe('ionView directive', function() { expect( beforeEnterData.direction ).toBe('forward'); expect( beforeEnterData.hasHeaderBar ).toBe(false); expect( beforeEnterData.navBarDelegate ).toBe(null); + expect( beforeEnterData.showNavBar ).toBe(true); })); it('should call ionNavViewController.beforeEnter with view-title attr', inject(function($rootScope) {