Skip to content

Commit 4216266

Browse files
committed
fix(loading): fix not hiding after two shows, always cancel delay
Fixes #1130
1 parent 14a2790 commit 4216266

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

gulpfile.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ gulp.task('docs', function(done) {
5555
return process.exit(1);
5656
}
5757
process.env.DOC_VERSION = docVersion;
58-
return dgeni('docs/docs.config.js').generateDocs().then(function() {
58+
return dgeni(__dirname + '/docs/docs.config.js').generateDocs().then(function() {
5959
gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
6060
});
6161
});
@@ -68,7 +68,7 @@ gulp.task('watch', ['build'], function() {
6868
});
6969

7070
gulp.task('changelog', function(done) {
71-
var file = argv.prepend ? 'CHANGELOG.md' : '';
71+
var file = argv.prepend ? __dirname + '/CHANGELOG.md' : '';
7272
var subtitle = argv.subtitle || '"' + pkg.codename + '"';
7373
var toHtml = !!argv.html;
7474
var dest = argv.dest || 'CHANGELOG.md';
@@ -352,10 +352,10 @@ gulp.task('cloudtest', ['protractor-sauce'], function(cb) {
352352
});
353353

354354
gulp.task('karma', function(cb) {
355-
return karma(cb, ['config/karma.conf.js', '--single-run=true']);
355+
return karma(cb, [__dirname + '/config/karma.conf.js', '--single-run=true']);
356356
});
357357
gulp.task('karma-watch', function(cb) {
358-
return karma(cb, ['config/karma.conf.js']);
358+
return karma(cb, [__dirname + '/config/karma.conf.js']);
359359
});
360360

361361
var connectServer;
@@ -378,7 +378,7 @@ function karma(cb, args) {
378378
args.push('--reporters='+argv.reporters.trim());
379379
}
380380
cp.spawn('node', [
381-
'./node_modules/karma/bin/karma',
381+
__dirname + '/node_modules/karma/bin/karma',
382382
'start'
383383
].concat(args), { stdio: 'inherit' })
384384
.on('exit', function(code) {

js/angular/service/loading.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
146146
options || (options = {});
147147
var delay = options.delay || options.showDelay || 0;
148148

149-
loadingShowDelay = $timeout(getLoader, delay).then(function(loader) {
149+
//If loading.show() was called previously, cancel it and show with our new options
150+
$timeout.cancel(loadingShowDelay);
151+
loadingShowDelay = $timeout(angular.noop, delay);
152+
153+
loadingShowDelay.then(getLoader).then(function(loader) {
150154
return loader.show(options);
151155
});
152156

@@ -164,7 +168,8 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
164168
}
165169

166170
function hideLoader() {
167-
loadingShowDelay.then(getLoader).then(function(loader) {
171+
$timeout.cancel(loadingShowDelay);
172+
getLoader().then(function(loader) {
168173
loader.hide();
169174
});
170175
}

test/html/loading.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
.controller('LoadingCtrl', function($scope, $ionicLoading) {
1919
$scope.startLoading = function() {
20-
window.loader = $ionicLoading.show({
20+
$ionicLoading.show({
2121
template: 'Getting current location...',
22-
duration: 4000
22+
delay: 100
2323
});
24+
$ionicLoading.show({
25+
template: 'Getting current location...',
26+
});
27+
$ionicLoading.hide();
2428
};
2529
});
2630
</script>

test/unit/angular/service/loading.unit.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,17 @@ describe('$ionicLoading service', function() {
112112
expect(loader.show).toHaveBeenCalledWith(options);
113113
}));
114114

115-
it('should hide', inject(function($ionicLoading, $rootScope) {
115+
it('should $timeout.cancel & hide', inject(function($ionicLoading, $rootScope, $timeout) {
116116
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
117+
spyOn($timeout, 'cancel');
117118
spyOn(loader, 'hide');
118119
$ionicLoading.hide();
120+
expect($timeout.cancel).toHaveBeenCalled();
119121
$rootScope.$apply();
120122
expect(loader.hide).toHaveBeenCalled();
121123
}));
122124

123-
it('hide should happen after show', inject(function($ionicLoading, $timeout) {
125+
it('hide should cancel show delay and just go ahead and hide', inject(function($ionicLoading, $timeout) {
124126
ionic.requestAnimationFrame = function(cb) { cb(); };
125127
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
126128
spyOn(loader, 'hide').andCallThrough();
@@ -130,7 +132,7 @@ describe('$ionicLoading service', function() {
130132
expect(loader.show).not.toHaveBeenCalled();
131133
expect(loader.hide).not.toHaveBeenCalled();
132134
$timeout.flush();
133-
expect(loader.show).toHaveBeenCalled();
135+
expect(loader.show).not.toHaveBeenCalled();
134136
expect(loader.hide).toHaveBeenCalled();
135137
expect(loader.isShown).toBe(false);
136138
expect(loader.element.hasClass('active')).toBe(false);

0 commit comments

Comments
 (0)