Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.

Allow ion-nav-bar to work in modals #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion js/angular/controller/navBarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
$element.addClass('nav-bar-container');
ionic.DomUtil.cachedAttr($element, 'nav-bar-transition', $ionicConfig.views.transition());

// check if the navbar is within a modal view
var ele = $element[0];
while((ele = ele.parentNode) && !/ion-modal-view/i.test(ele.tagName));
self.inModal = !!ele;

// create two nav bar blocks which will trade out which one is shown
self.createHeaderBar(false);
self.createHeaderBar(true);
Expand Down Expand Up @@ -372,7 +377,10 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io

// set non primary to hide second
for (var x = 0; x < $ionicNavBarDelegate._instances.length; x++) {
if ($ionicNavBarDelegate._instances[x] !== self) $ionicNavBarDelegate._instances[x].visibleBar(false);
var instance = $ionicNavBarDelegate._instances[x];
if (instance !== self && self.inModal === instance.inModal) {
instance.visibleBar(false);
}
}
};

Expand Down
5 changes: 2 additions & 3 deletions js/angular/controller/viewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ function($scope, $element, $attrs, $compile, $rootScope) {
self.init = function() {
deregIonNavBarInit();

var modalCtrl = $element.inheritedData('$ionModalController');
navViewCtrl = $element.inheritedData('$ionNavViewController');

// don't bother if inside a modal or there's no parent navView
if (!navViewCtrl || modalCtrl) return;
// don't bother if there's no parent navView
if (!navViewCtrl) return;

// add listeners for when this view changes
$scope.$on('$ionicView.beforeEnter', self.beforeEnter);
Expand Down