Skip to content

Commit

Permalink
fix($ionicLoading): stop race condition with show and hide
Browse files Browse the repository at this point in the history
Fixes #1100.
  • Loading branch information
ajoslin authored and tlancina committed Apr 12, 2014
1 parent 5e4ed74 commit 32d1653
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 0 additions & 2 deletions js/ext/angular/src/directive/ionicNavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
this._animateTitles = function() {
var oldTitleEl, newTitleEl, currentTitles;

console.log('animateTItles');

//If we have any title right now
//(or more than one, they could be transitioning on switch),
//replace the first one with an oldTitle element
Expand Down
19 changes: 10 additions & 9 deletions js/ext/angular/src/service/ionicLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,19 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
}
});

this.isShown = true;
ionic.requestAnimationFrame(function() {
$animate.removeClass(self.element, 'ng-hide');
//Fix for ios: if we center the element twice, it always gets
//position right. Otherwise, it doesn't
ionic.DomUtil.centerElementByMargin(self.element[0]);
//One frame after it's visible, position it
ionic.requestAnimationFrame(function() {
if (self.isShown) {
$animate.removeClass(self.element, 'ng-hide');
//Fix for ios: if we center the element twice, it always gets
//position right. Otherwise, it doesn't
ionic.DomUtil.centerElementByMargin(self.element[0]);
});
//One frame after it's visible, position it
ionic.requestAnimationFrame(function() {
ionic.DomUtil.centerElementByMargin(self.element[0]);
});
}
});

this.isShown = true;
};
loader.hide = function() {
if (this.isShown) {
Expand Down
14 changes: 14 additions & 0 deletions js/ext/angular/test/service/ionicLoading.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ describe('$ionicLoading service', function() {
expect(loader.isShown).toBe(false);
expect(loader.element.hasClass('ng-hide')).toBe(true);
}));
it('show should only removeClass after raf is still isShown', inject(function($ionicLoading) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
var rafCallback;
ionic.requestAnimationFrame = function(cb) {
rafCallback = cb;
};
loader.show({});
expect(loader.isShown).toBe(true);
loader.hide();
expect(loader.isShown).toBe(false);
rafCallback();
expect(loader.element.hasClass('ng-hide')).toBe(true);
ionic.requestAnimationFrame = function(cb) { cb(); };
}));

});
});

0 comments on commit 32d1653

Please sign in to comment.