Skip to content

Commit b97900f

Browse files
committed
Fixed #167 and #312 - nav bar router issues
1 parent 6e62d37 commit b97900f

File tree

2 files changed

+94
-58
lines changed

2 files changed

+94
-58
lines changed

dist/js/ionic-angular.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,11 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
11681168
template: '<header class="bar bar-header nav-bar" ng-class="{invisible: !navController.navBar.isVisible}">' +
11691169
'<div class="buttons"> ' +
11701170
'<button nav-back class="button" ng-if="enableBackButton && showBackButton" ng-class="backButtonClass" ng-bind-html="backButtonLabel"></button>' +
1171-
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button {{button.type}}" ng-bind-html="button.content"></button>' +
1171+
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
11721172
'</div>' +
11731173
'<h1 class="title" ng-bind="currentTitle"></h1>' +
11741174
'<div class="buttons" ng-if="rightButtons.length"> ' +
1175-
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button {{button.type}}" ng-bind-html="button.content"></button>' +
1175+
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
11761176
'</div>' +
11771177
'</header>',
11781178
link: function($scope, $element, $attr, navCtrl) {
@@ -1234,6 +1234,14 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
12341234
}
12351235
};
12361236

1237+
$scope.$parent.$on('navRouter.showBackButton', function(e, data) {
1238+
$scope.enableBackButton = true;
1239+
});
1240+
1241+
$scope.$parent.$on('navRouter.hideBackButton', function(e, data) {
1242+
$scope.enableBackButton = false;
1243+
});
1244+
12371245
// Listen for changes on title change, and update the title
12381246
$scope.$parent.$on('navRouter.pageChanged', function(e, data) {
12391247
updateHeaderData(data);
@@ -1289,57 +1297,67 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
12891297
.directive('navPage', ['$parse', function($parse) {
12901298
return {
12911299
restrict: 'E',
1292-
scope: true,
12931300
require: '^navRouter',
1301+
scope: {
1302+
leftButtons: '=',
1303+
rightButtons: '=',
1304+
title: '=',
1305+
icon: '@',
1306+
iconOn: '@',
1307+
iconOff: '@',
1308+
type: '@',
1309+
alignTitle: '@',
1310+
hideBackButton: '@',
1311+
hideNavBar: '@',
1312+
animate: '@',
1313+
},
12941314
link: function($scope, $element, $attr, navCtrl) {
12951315
$element.addClass('pane');
12961316

1297-
$scope.icon = $attr.icon;
1298-
$scope.iconOn = $attr.iconOn;
1299-
$scope.iconOff = $attr.iconOff;
1300-
13011317
// Should we hide a back button when this tab is shown
1302-
$scope.hideBackButton = $scope.$eval($attr.hideBackButton);
1318+
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
13031319

1304-
$scope.hideNavBar = $scope.$eval($attr.hideNavBar);
1320+
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
13051321

13061322
navCtrl.navBar.isVisible = !$scope.hideNavBar;
13071323

1324+
if($scope.hideBackButton === true) {
1325+
$scope.$emit('navRouter.hideBackButton');
1326+
} else {
1327+
$scope.$emit('navRouter.showBackButton');
1328+
}
1329+
13081330
// Whether we should animate on tab change, also impacts whether we
13091331
// tell any parent nav controller to animate
1310-
$scope.animate = $scope.$eval($attr.animate);
1311-
1312-
// Grab whether we should update any parent nav router on tab changes
1313-
$scope.doesUpdateNavRouter = $scope.$eval($attr.doesUpdateNavRouter) || true;
1332+
$scope.animate = $scope.$eval($scope.animate);
1333+
13141334

13151335
// watch for changes in the left buttons
1316-
var leftButtonsGet = $parse($attr.leftButtons);
1317-
$scope.$watch(leftButtonsGet, function(value) {
1318-
$scope.leftButtons = value;
1319-
if($scope.doesUpdateNavRouter) {
1320-
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
1321-
}
1336+
$scope.$watch('leftButtons', function(value) {
1337+
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
13221338
});
13231339

1324-
// watch for changes in the right buttons
1325-
var rightButtonsGet = $parse($attr.rightButtons);
1326-
$scope.$watch(rightButtonsGet, function(value) {
1327-
$scope.rightButtons = value;
1328-
if($scope.doesUpdateNavRouter) {
1329-
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
1340+
$scope.$watch('rightButtons', function(val) {
1341+
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
1342+
});
1343+
1344+
/*
1345+
$scope.$watch('hideBackButton', function(value) {
1346+
if(value === true) {
1347+
navCtrl.hideBackButton();
1348+
} else {
1349+
navCtrl.showBackButton();
13301350
}
13311351
});
1352+
*/
13321353

13331354
// watch for changes in the title
1334-
var titleGet = $parse($attr.title);
1335-
$scope.$watch(titleGet, function(value) {
1336-
$scope.title = value;
1355+
$scope.$watch('title', function(value) {
13371356
$scope.$emit('navRouter.titleChanged', {
13381357
title: value,
13391358
animate: $scope.animate
13401359
});
13411360
});
1342-
13431361
}
13441362
};
13451363
}])

js/ext/angular/src/directive/ionicNavRouter.js

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
195195
template: '<header class="bar bar-header nav-bar" ng-class="{invisible: !navController.navBar.isVisible}">' +
196196
'<div class="buttons"> ' +
197197
'<button nav-back class="button" ng-if="enableBackButton && showBackButton" ng-class="backButtonClass" ng-bind-html="backButtonLabel"></button>' +
198-
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button {{button.type}}" ng-bind-html="button.content"></button>' +
198+
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
199199
'</div>' +
200200
'<h1 class="title" ng-bind="currentTitle"></h1>' +
201201
'<div class="buttons" ng-if="rightButtons.length"> ' +
202-
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button {{button.type}}" ng-bind-html="button.content"></button>' +
202+
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" class="button no-animation {{button.type}}" ng-bind-html="button.content"></button>' +
203203
'</div>' +
204204
'</header>',
205205
link: function($scope, $element, $attr, navCtrl) {
@@ -261,6 +261,14 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
261261
}
262262
};
263263

264+
$scope.$parent.$on('navRouter.showBackButton', function(e, data) {
265+
$scope.enableBackButton = true;
266+
});
267+
268+
$scope.$parent.$on('navRouter.hideBackButton', function(e, data) {
269+
$scope.enableBackButton = false;
270+
});
271+
264272
// Listen for changes on title change, and update the title
265273
$scope.$parent.$on('navRouter.pageChanged', function(e, data) {
266274
updateHeaderData(data);
@@ -316,57 +324,67 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
316324
.directive('navPage', ['$parse', function($parse) {
317325
return {
318326
restrict: 'E',
319-
scope: true,
320327
require: '^navRouter',
328+
scope: {
329+
leftButtons: '=',
330+
rightButtons: '=',
331+
title: '=',
332+
icon: '@',
333+
iconOn: '@',
334+
iconOff: '@',
335+
type: '@',
336+
alignTitle: '@',
337+
hideBackButton: '@',
338+
hideNavBar: '@',
339+
animate: '@',
340+
},
321341
link: function($scope, $element, $attr, navCtrl) {
322342
$element.addClass('pane');
323343

324-
$scope.icon = $attr.icon;
325-
$scope.iconOn = $attr.iconOn;
326-
$scope.iconOff = $attr.iconOff;
327-
328344
// Should we hide a back button when this tab is shown
329-
$scope.hideBackButton = $scope.$eval($attr.hideBackButton);
345+
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
330346

331-
$scope.hideNavBar = $scope.$eval($attr.hideNavBar);
347+
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
332348

333349
navCtrl.navBar.isVisible = !$scope.hideNavBar;
334350

351+
if($scope.hideBackButton === true) {
352+
$scope.$emit('navRouter.hideBackButton');
353+
} else {
354+
$scope.$emit('navRouter.showBackButton');
355+
}
356+
335357
// Whether we should animate on tab change, also impacts whether we
336358
// tell any parent nav controller to animate
337-
$scope.animate = $scope.$eval($attr.animate);
338-
339-
// Grab whether we should update any parent nav router on tab changes
340-
$scope.doesUpdateNavRouter = $scope.$eval($attr.doesUpdateNavRouter) || true;
359+
$scope.animate = $scope.$eval($scope.animate);
360+
341361

342362
// watch for changes in the left buttons
343-
var leftButtonsGet = $parse($attr.leftButtons);
344-
$scope.$watch(leftButtonsGet, function(value) {
345-
$scope.leftButtons = value;
346-
if($scope.doesUpdateNavRouter) {
347-
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
348-
}
363+
$scope.$watch('leftButtons', function(value) {
364+
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
365+
});
366+
367+
$scope.$watch('rightButtons', function(val) {
368+
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
349369
});
350370

351-
// watch for changes in the right buttons
352-
var rightButtonsGet = $parse($attr.rightButtons);
353-
$scope.$watch(rightButtonsGet, function(value) {
354-
$scope.rightButtons = value;
355-
if($scope.doesUpdateNavRouter) {
356-
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
371+
/*
372+
$scope.$watch('hideBackButton', function(value) {
373+
if(value === true) {
374+
navCtrl.hideBackButton();
375+
} else {
376+
navCtrl.showBackButton();
357377
}
358378
});
379+
*/
359380

360381
// watch for changes in the title
361-
var titleGet = $parse($attr.title);
362-
$scope.$watch(titleGet, function(value) {
363-
$scope.title = value;
382+
$scope.$watch('title', function(value) {
364383
$scope.$emit('navRouter.titleChanged', {
365384
title: value,
366385
animate: $scope.animate
367386
});
368387
});
369-
370388
}
371389
};
372390
}])

0 commit comments

Comments
 (0)