Skip to content

Commit eb1dee9

Browse files
committed
fix($ionicLoading): stop race condition with show and hide
Fixes #1100.
1 parent 56eb2cf commit eb1dee9

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

js/ext/angular/src/directive/ionicNavBar.js

-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
191191
this._animateTitles = function() {
192192
var oldTitleEl, newTitleEl, currentTitles;
193193

194-
console.log('animateTItles');
195-
196194
//If we have any title right now
197195
//(or more than one, they could be transitioning on switch),
198196
//replace the first one with an oldTitle element

js/ext/angular/src/service/ionicLoading.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,19 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
111111
}
112112
});
113113

114+
this.isShown = true;
114115
ionic.requestAnimationFrame(function() {
115-
$animate.removeClass(self.element, 'ng-hide');
116-
//Fix for ios: if we center the element twice, it always gets
117-
//position right. Otherwise, it doesn't
118-
ionic.DomUtil.centerElementByMargin(self.element[0]);
119-
//One frame after it's visible, position it
120-
ionic.requestAnimationFrame(function() {
116+
if (self.isShown) {
117+
$animate.removeClass(self.element, 'ng-hide');
118+
//Fix for ios: if we center the element twice, it always gets
119+
//position right. Otherwise, it doesn't
121120
ionic.DomUtil.centerElementByMargin(self.element[0]);
122-
});
121+
//One frame after it's visible, position it
122+
ionic.requestAnimationFrame(function() {
123+
ionic.DomUtil.centerElementByMargin(self.element[0]);
124+
});
125+
}
123126
});
124-
125-
this.isShown = true;
126127
};
127128
loader.hide = function() {
128129
if (this.isShown) {

js/ext/angular/test/service/ionicLoading.unit.js

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ describe('$ionicLoading service', function() {
134134
expect(loader.isShown).toBe(false);
135135
expect(loader.element.hasClass('ng-hide')).toBe(true);
136136
}));
137+
it('show should only removeClass after raf is still isShown', inject(function($ionicLoading) {
138+
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
139+
var rafCallback;
140+
ionic.requestAnimationFrame = function(cb) {
141+
rafCallback = cb;
142+
};
143+
loader.show({});
144+
expect(loader.isShown).toBe(true);
145+
loader.hide();
146+
expect(loader.isShown).toBe(false);
147+
rafCallback();
148+
expect(loader.element.hasClass('ng-hide')).toBe(true);
149+
ionic.requestAnimationFrame = function(cb) { cb(); };
150+
}));
137151

138152
});
139153
});

0 commit comments

Comments
 (0)