Skip to content

Commit 7281e2a

Browse files
maitaiajoslin
authored andcommitted
fix(loading): make showDelay option work correctly
The 'showDelay' configuration option of $ionicLoading exists but does not lead to any delay whatsoever. This change implements that functionality. Closes #562
1 parent 70d9524 commit 7281e2a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

js/views/loadingView.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(function(ionic) {
22
'use strict';
33
/**
4-
* An ActionSheet is the slide up menu popularized on iOS.
4+
* Loading
55
*
6-
* You see it all over iOS apps, where it offers a set of options
7-
* triggered after an action.
6+
* The Loading is an overlay that can be used to indicate
7+
* activity while blocking user interaction.
88
*/
99
ionic.views.Loading = ionic.views.View.inherit({
1010
initialize: function(opts) {
@@ -14,6 +14,8 @@
1414

1515
this.maxWidth = opts.maxWidth || 200;
1616

17+
this.showDelay = opts.showDelay || 0;
18+
1719
this._loadingBox = this.el.querySelector('.loading');
1820
},
1921
show: function() {
@@ -29,13 +31,19 @@
2931
lb.style.marginLeft = (-lb.offsetWidth) / 2 + 'px';
3032
lb.style.marginTop = (-lb.offsetHeight) / 2 + 'px';
3133

32-
_this.el.classList.add('active');
34+
// Wait 'showDelay' ms before showing the loading screen
35+
this._showDelayTimeout = window.setTimeout(function() {
36+
_this.el.classList.add('active');
37+
}, _this.showDelay);
3338
}
3439
},
3540
hide: function() {
3641
// Force a reflow so the animation will actually run
3742
this.el.offsetWidth;
3843

44+
// Prevent unnecessary 'show' after 'hide' has already been called
45+
window.clearTimeout(this._showDelayTimeout);
46+
3947
this.el.classList.remove('active');
4048
}
4149
});

0 commit comments

Comments
 (0)