@@ -5,14 +5,99 @@ import {Animation} from '../../animations/animation';
5
5
import { Transition , TransitionOptions } from '../../transitions/transition' ;
6
6
import { Config } from '../../config/config' ;
7
7
import { Spinner } from '../spinner/spinner' ;
8
- import { isPresent } from '../../util/util' ;
8
+ import { isPresent , isUndefined , isDefined } from '../../util/util' ;
9
9
import { NavParams } from '../nav/nav-params' ;
10
10
import { ViewController } from '../nav/view-controller' ;
11
11
12
12
13
13
/**
14
14
* @name Loading
15
15
* @description
16
+ * An overlay that can be used to indicate activity while blocking user
17
+ * interaction. The loading indicator appears on top of the app's content,
18
+ * and can be automatically dismissed by the app or manually dismissed by
19
+ * the user to resume interaction with the app. It includes an optional
20
+ * backdrop, which can optionally be clicked to dismiss the loading
21
+ * indicator.
22
+ *
23
+ * ### Creating
24
+ * You can pass all of the loading options in the first argument of
25
+ * the create method: `Loading.create(opts)`. The spinner name should be
26
+ * passed in the `spinner` property, and any optional HTML can be passed
27
+ * in the `content` property. If you do not pass a value to `spinner`
28
+ * the loading indicator will use the spinner specified by the mode. To
29
+ * set the spinner name across the app, set the value of `loadingSpinner`
30
+ * in your app's config. To hide the spinner, you can set
31
+ * `loadingSpinner: 'hide'` or pass `spinner: 'hide'` in the loading
32
+ * options. See the create method below for all available options.
33
+ *
34
+ * ### Dismissing
35
+ * The loading indicator can be dismissed automatically after a specific
36
+ * amount of time by passing the number of milliseconds to display it in
37
+ * the `duration` of the loading options. It can also be dismissed by
38
+ * clicking on the backdrop or pressing the escape key if
39
+ * `enableBackdropDismiss` is set to `true` in the loading options. By
40
+ * default the loading indicator will show even during page changes,
41
+ * but this can be disabled by setting `dismissOnPageChange` to `true`.
42
+ * To dismiss the loading indicator after creation, call the `dismiss()`
43
+ * method on the Loading instance.
44
+ *
45
+ * ### Limitations
46
+ * The element is styled to appear on top of other content by setting its
47
+ * `z-index` property. You must ensure no element has a stacking context with
48
+ * a higher `z-index` than this element.
49
+ *
50
+ * @usage
51
+ * ```ts
52
+ * constructor(nav: NavController) {
53
+ * this.nav = nav;
54
+ * }
55
+ *
56
+ * presentLoadingDefault() {
57
+ * let loading = Loading.create({
58
+ * content: 'Please wait...'
59
+ * });
60
+ *
61
+ * this.nav.present(loading);
62
+ *
63
+ * setTimeout(() => {
64
+ * loading.dismiss();
65
+ * }, 5000);
66
+ * }
67
+ *
68
+ * presentLoadingCustom() {
69
+ * let loading = Loading.create({
70
+ * spinner: 'hide',
71
+ * content: `
72
+ * <div class="custom-spinner-container">
73
+ * <div class="custom-spinner-box"></div>
74
+ * </div>`,
75
+ * duration: 5000
76
+ * });
77
+ *
78
+ * this.nav.present(loading);
79
+ * }
80
+ *
81
+ * presentLoadingText() {
82
+ * let loading = Loading.create({
83
+ * spinner: 'hide',
84
+ * content: 'Loading Please Wait...'
85
+ * });
86
+ *
87
+ * this.nav.present(loading);
88
+ *
89
+ * setTimeout(() => {
90
+ * this.nav.push(Page2);
91
+ * }, 1000);
92
+ *
93
+ * setTimeout(() => {
94
+ * loading.dismiss();
95
+ * }, 5000);
96
+ * }
97
+ * ```
98
+ *
99
+ * @demo /docs/v2/demos/loading/
100
+ * @see {@link /docs/v2/api/components/spinner/Spinner Spinner API Docs }
16
101
*/
17
102
export class Loading extends ViewController {
18
103
@@ -39,11 +124,11 @@ export class Loading extends ViewController {
39
124
}
40
125
41
126
/**
42
- * Open a loading indicator with the following options
127
+ * Create a loading indicator with the following options
43
128
*
44
129
* | Option | Type | Description |
45
130
* |-----------------------|------------|------------------------------------------------------------------------------------------------------------------|
46
- * | icon |`string` | The spinner icon for the loading indicator. |
131
+ * | spinner |`string` | The name of the SVG spinner for the loading indicator. |
47
132
* | content |`string` | The html content for the loading indicator. |
48
133
* | cssClass |`string` | An additional class for custom styles. |
49
134
* | showBackdrop |`boolean` | Whether to show the backdrop. Default true. |
@@ -69,8 +154,8 @@ export class Loading extends ViewController {
69
154
template :
70
155
'<div (click)="bdClick()" tappable disable-activated class="backdrop" [class.hide-backdrop]="!d.showBackdrop" role="presentation"></div>' +
71
156
'<div class="loading-wrapper">' +
72
- '<div *ngIf="d.icon " class="loading-spinner">' +
73
- '<ion-spinner [name]="d.icon == \'platform\' ? null : d.icon "></ion-spinner>' +
157
+ '<div *ngIf="showSpinner " class="loading-spinner">' +
158
+ '<ion-spinner [name]="d.spinner "></ion-spinner>' +
74
159
'</div>' +
75
160
'<div *ngIf="d.content" [innerHTML]="d.content" class="loading-content"></div>' +
76
161
'</div>' ,
@@ -83,6 +168,7 @@ class LoadingCmp {
83
168
private d : any ;
84
169
private id : number ;
85
170
private created : number ;
171
+ private showSpinner : boolean ;
86
172
87
173
constructor (
88
174
private _viewCtrl : ViewController ,
@@ -101,6 +187,17 @@ class LoadingCmp {
101
187
this . id = ( ++ loadingIds ) ;
102
188
}
103
189
190
+ ngOnInit ( ) {
191
+ // If no spinner was passed in loading options we need to fall back
192
+ // to the loadingSpinner in the app's config, then the mode spinner
193
+ if ( isUndefined ( this . d . spinner ) ) {
194
+ this . d . spinner = this . _config . get ( 'loadingSpinner' , this . _config . get ( 'spinner' , 'ios' ) ) ;
195
+ }
196
+
197
+ // If the user passed hide to the spinner we don't want to show it
198
+ this . showSpinner = isDefined ( this . d . spinner ) && this . d . spinner !== 'hide' ;
199
+ }
200
+
104
201
onPageDidEnter ( ) {
105
202
let activeElement : any = document . activeElement ;
106
203
if ( document . activeElement ) {
@@ -138,7 +235,7 @@ class LoadingCmp {
138
235
}
139
236
140
237
export interface LoadingOptions {
141
- icon ?: string ;
238
+ spinner ?: string ;
142
239
content ?: string ;
143
240
showBackdrop ?: boolean ;
144
241
dismissOnPageChange ?: boolean ;
0 commit comments