Skip to content

Commit

Permalink
fix(loading): fix not hiding after two shows, always cancel delay
Browse files Browse the repository at this point in the history
Fixes #1130
  • Loading branch information
ajoslin committed Apr 14, 2014
1 parent 14a2790 commit 4216266
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ gulp.task('docs', function(done) {
return process.exit(1);
}
process.env.DOC_VERSION = docVersion;
return dgeni('docs/docs.config.js').generateDocs().then(function() {
return dgeni(__dirname + '/docs/docs.config.js').generateDocs().then(function() {
gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
});
});
Expand All @@ -68,7 +68,7 @@ gulp.task('watch', ['build'], function() {
});

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

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

var connectServer;
Expand All @@ -378,7 +378,7 @@ function karma(cb, args) {
args.push('--reporters='+argv.reporters.trim());
}
cp.spawn('node', [
'./node_modules/karma/bin/karma',
__dirname + '/node_modules/karma/bin/karma',
'start'
].concat(args), { stdio: 'inherit' })
.on('exit', function(code) {
Expand Down
9 changes: 7 additions & 2 deletions js/angular/service/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
options || (options = {});
var delay = options.delay || options.showDelay || 0;

loadingShowDelay = $timeout(getLoader, delay).then(function(loader) {
//If loading.show() was called previously, cancel it and show with our new options
$timeout.cancel(loadingShowDelay);
loadingShowDelay = $timeout(angular.noop, delay);

loadingShowDelay.then(getLoader).then(function(loader) {
return loader.show(options);
});

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

function hideLoader() {
loadingShowDelay.then(getLoader).then(function(loader) {
$timeout.cancel(loadingShowDelay);
getLoader().then(function(loader) {
loader.hide();
});
}
Expand Down
8 changes: 6 additions & 2 deletions test/html/loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

.controller('LoadingCtrl', function($scope, $ionicLoading) {
$scope.startLoading = function() {
window.loader = $ionicLoading.show({
$ionicLoading.show({
template: 'Getting current location...',
duration: 4000
delay: 100
});
$ionicLoading.show({
template: 'Getting current location...',
});
$ionicLoading.hide();
};
});
</script>
Expand Down
8 changes: 5 additions & 3 deletions test/unit/angular/service/loading.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ describe('$ionicLoading service', function() {
expect(loader.show).toHaveBeenCalledWith(options);
}));

it('should hide', inject(function($ionicLoading, $rootScope) {
it('should $timeout.cancel & hide', inject(function($ionicLoading, $rootScope, $timeout) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
spyOn($timeout, 'cancel');
spyOn(loader, 'hide');
$ionicLoading.hide();
expect($timeout.cancel).toHaveBeenCalled();
$rootScope.$apply();
expect(loader.hide).toHaveBeenCalled();
}));

it('hide should happen after show', inject(function($ionicLoading, $timeout) {
it('hide should cancel show delay and just go ahead and hide', inject(function($ionicLoading, $timeout) {
ionic.requestAnimationFrame = function(cb) { cb(); };
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
spyOn(loader, 'hide').andCallThrough();
Expand All @@ -130,7 +132,7 @@ describe('$ionicLoading service', function() {
expect(loader.show).not.toHaveBeenCalled();
expect(loader.hide).not.toHaveBeenCalled();
$timeout.flush();
expect(loader.show).toHaveBeenCalled();
expect(loader.show).not.toHaveBeenCalled();
expect(loader.hide).toHaveBeenCalled();
expect(loader.isShown).toBe(false);
expect(loader.element.hasClass('active')).toBe(false);
Expand Down

0 comments on commit 4216266

Please sign in to comment.