@@ -5,14 +5,99 @@ import {Animation} from '../../animations/animation';
55import { Transition , TransitionOptions } from '../../transitions/transition' ;
66import { Config } from '../../config/config' ;
77import { Spinner } from '../spinner/spinner' ;
8- import { isPresent } from '../../util/util' ;
8+ import { isPresent , isUndefined , isDefined } from '../../util/util' ;
99import { NavParams } from '../nav/nav-params' ;
1010import { ViewController } from '../nav/view-controller' ;
1111
1212
1313/**
1414 * @name Loading
1515 * @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 }
16101 */
17102export class Loading extends ViewController {
18103
@@ -39,11 +124,11 @@ export class Loading extends ViewController {
39124 }
40125
41126 /**
42- * Open a loading indicator with the following options
127+ * Create a loading indicator with the following options
43128 *
44129 * | Option | Type | Description |
45130 * |-----------------------|------------|------------------------------------------------------------------------------------------------------------------|
46- * | icon |`string` | The spinner icon for the loading indicator. |
131+ * | spinner |`string` | The name of the SVG spinner for the loading indicator. |
47132 * | content |`string` | The html content for the loading indicator. |
48133 * | cssClass |`string` | An additional class for custom styles. |
49134 * | showBackdrop |`boolean` | Whether to show the backdrop. Default true. |
@@ -69,8 +154,8 @@ export class Loading extends ViewController {
69154 template :
70155 '<div (click)="bdClick()" tappable disable-activated class="backdrop" [class.hide-backdrop]="!d.showBackdrop" role="presentation"></div>' +
71156 '<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>' +
74159 '</div>' +
75160 '<div *ngIf="d.content" [innerHTML]="d.content" class="loading-content"></div>' +
76161 '</div>' ,
@@ -83,6 +168,7 @@ class LoadingCmp {
83168 private d : any ;
84169 private id : number ;
85170 private created : number ;
171+ private showSpinner : boolean ;
86172
87173 constructor (
88174 private _viewCtrl : ViewController ,
@@ -101,6 +187,17 @@ class LoadingCmp {
101187 this . id = ( ++ loadingIds ) ;
102188 }
103189
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+
104201 onPageDidEnter ( ) {
105202 let activeElement : any = document . activeElement ;
106203 if ( document . activeElement ) {
@@ -138,7 +235,7 @@ class LoadingCmp {
138235}
139236
140237export interface LoadingOptions {
141- icon ?: string ;
238+ spinner ?: string ;
142239 content ?: string ;
143240 showBackdrop ?: boolean ;
144241 dismissOnPageChange ?: boolean ;
0 commit comments