Skip to content

Commit

Permalink
fix(navBar): only add default animation if there is no custom animation
Browse files Browse the repository at this point in the history
Closes #1671
  • Loading branch information
ajoslin committed Jul 7, 2014
1 parent 22a81fe commit cdba48f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions js/angular/directive/navBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ IonicModule.constant('$ionicNavBarConfig', {
* We can add buttons depending on the currently visible view using
* {@link ionic.directive:ionNavButtons}.
*
* Assign an [animation class](/docs/components#animations) to the element to
* enable animated changing of titles (recommended: 'nav-title-slide-ios7')
* Add an [animation class](/docs/components#animations) to the element via the
* `animation` attribute to enable animated changing of titles
* (recommended: 'nav-title-slide-ios7').
*
* Note that the ion-nav-bar element will only work correctly if your content has an
* ionView around it.
Expand All @@ -32,7 +33,7 @@ IonicModule.constant('$ionicNavBarConfig', {
* ```html
* <body ng-app="starter">
* <!-- The nav bar that will be updated as we navigate -->
* <ion-nav-bar class="bar-positive nav-title-slide-ios7">
* <ion-nav-bar class="bar-positive" animation="nav-title-slide-ios7">
* </ion-nav-bar>
*
* <!-- where the initial view template will be rendered -->
Expand Down Expand Up @@ -94,7 +95,7 @@ function($ionicViewService, $rootScope, $animate, $compile, $ionicNavBarConfig)
compile: function(tElement, tAttrs) {
//We cannot transclude here because it breaks element.data() inheritance on compile
tElement
.addClass('bar bar-header nav-bar ' + $ionicNavBarConfig.transition)
.addClass('bar bar-header nav-bar')
.append(
'<div class="buttons left-buttons"> ' +
'</div>' +
Expand All @@ -103,6 +104,12 @@ function($ionicViewService, $rootScope, $animate, $compile, $ionicNavBarConfig)
'</div>'
);

if (isDefined(tAttrs.animation)) {
tElement.addClass(tAttrs.animation);
} else {
tElement.addClass($ionicNavBarConfig.transition);
}

return { pre: prelink };
function prelink($scope, $element, $attr, navBarCtrl) {
navBarCtrl._headerBarView = new ionic.views.HeaderBar({
Expand Down
12 changes: 12 additions & 0 deletions test/unit/angular/directive/navBar.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ describe('ionNavBar', function() {
var el = setup();
expect(el.hasClass('nav-title-slide-ios7')).toBe(true);
});

it('should not add transition if animation attribute is defined', function() {
var el = setup('animation="123abc"');
expect(el.hasClass('123abc')).toBe(true);
expect(el.hasClass('nav-title-slide-ios7')).toBe(false);
});
});

describe('Android', function() {
Expand All @@ -346,6 +352,12 @@ describe('ionNavBar', function() {
// Nav bar titles don't animation by default on Android
expect(el.hasClass('no-animation')).toBe(true);
});

it('should not add transition if animation attribute is defined', function() {
var el = setup('animation="123abc"');
expect(el.hasClass('123abc')).toBe(true);
expect(el.hasClass('no-animation')).toBe(false);
});
});
});
});

0 comments on commit cdba48f

Please sign in to comment.