mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor($ionicLoading): make sure .hide() always happens after .show()
Fixes #1085. Thanks @graemefoster.
This commit is contained in:
6
js/ext/angular/src/service/ionicLoading.js
vendored
6
js/ext/angular/src/service/ionicLoading.js
vendored
@@ -45,6 +45,8 @@ angular.module('ionic.service.loading', [])
|
||||
function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log) {
|
||||
|
||||
var loaderInstance;
|
||||
//default value
|
||||
var loadingShowDelay = $q.when();
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -135,7 +137,7 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
|
||||
deprecated.field(SHOW_DELAY_LOADING_DEPRECATED, $log.warn, options, 'showDelay', options.showDelay);
|
||||
deprecated.field(SHOW_BACKDROP_LOADING_DEPRECATED, $log.warn, options, 'showBackdrop', options.showBackdrop);
|
||||
|
||||
$timeout(getLoader, options.delay || options.showDelay || 0)
|
||||
loadingShowDelay = $timeout(getLoader, options.delay || options.showDelay || 0)
|
||||
.then(function(loader) {
|
||||
return loader.show(options);
|
||||
});
|
||||
@@ -154,7 +156,7 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
|
||||
}
|
||||
|
||||
function hideLoader() {
|
||||
getLoader().then(function(loader) {
|
||||
loadingShowDelay.then(getLoader).then(function(loader) {
|
||||
loader.hide();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,5 +103,21 @@ describe('$ionicLoading service', function() {
|
||||
expect(loader.hide).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('hide should happen after show', inject(function($ionicLoading, $timeout) {
|
||||
ionic.requestAnimationFrame = function(cb) { cb(); };
|
||||
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
|
||||
spyOn(loader, 'hide').andCallThrough();
|
||||
spyOn(loader, 'show').andCallThrough();
|
||||
$ionicLoading.show({ delay: 1000 });
|
||||
$ionicLoading.hide();
|
||||
expect(loader.show).not.toHaveBeenCalled();
|
||||
expect(loader.hide).not.toHaveBeenCalled();
|
||||
$timeout.flush();
|
||||
expect(loader.show).toHaveBeenCalled();
|
||||
expect(loader.hide).toHaveBeenCalled();
|
||||
expect(loader.isShown).toBe(false);
|
||||
expect(loader.element.hasClass('ng-hide')).toBe(true);
|
||||
}));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user