mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 13:01:01 +08:00

Internal refactor completed in order to improve tree shaking and dead code removal. The public API, with an exception to ion-slides, has stayed the same. However, internally many changes were required so bundlers could better exclude modules which should not be bundled. Ultimately most changes resorted to removing references to `window` or `document`, or a module that referenced one of those. BREAKING CHANGES ion-slides was refactored to remove the external dependencies, and rewritten in TypeScript/ES6 modules to again improve tree shaking abilities.
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import { Component, ElementRef, Renderer, ViewEncapsulation } from '@angular/core';
|
|
|
|
import { Config } from '../../config/config';
|
|
import { GestureController, BlockerDelegate, BLOCK_ALL } from '../../gestures/gesture-controller';
|
|
import { isDefined, isUndefined, assert } from '../../util/util';
|
|
import { LoadingOptions } from './loading-options';
|
|
import { NavParams } from '../../navigation/nav-params';
|
|
import { Platform } from '../../platform/platform';
|
|
import { ViewController } from '../../navigation/view-controller';
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
@Component({
|
|
selector: 'ion-loading',
|
|
template:
|
|
'<ion-backdrop [hidden]="!d.showBackdrop"></ion-backdrop>' +
|
|
'<div class="loading-wrapper">' +
|
|
'<div *ngIf="showSpinner" class="loading-spinner">' +
|
|
'<ion-spinner [name]="d.spinner"></ion-spinner>' +
|
|
'</div>' +
|
|
'<div *ngIf="d.content" [innerHTML]="d.content" class="loading-content"></div>' +
|
|
'</div>',
|
|
host: {
|
|
'role': 'dialog'
|
|
},
|
|
encapsulation: ViewEncapsulation.None,
|
|
})
|
|
export class LoadingCmp {
|
|
d: LoadingOptions;
|
|
id: number;
|
|
showSpinner: boolean;
|
|
durationTimeout: number;
|
|
gestureBlocker: BlockerDelegate;
|
|
|
|
constructor(
|
|
private _viewCtrl: ViewController,
|
|
private _config: Config,
|
|
private _plt: Platform,
|
|
private _elementRef: ElementRef,
|
|
gestureCtrl: GestureController,
|
|
params: NavParams,
|
|
renderer: Renderer
|
|
) {
|
|
assert(params.data, 'params data must be valid');
|
|
this.gestureBlocker = gestureCtrl.createBlocker(BLOCK_ALL);
|
|
this.d = params.data;
|
|
|
|
renderer.setElementClass(_elementRef.nativeElement, `loading-${_config.get('mode')}`, true);
|
|
|
|
if (this.d.cssClass) {
|
|
this.d.cssClass.split(' ').forEach(cssClass => {
|
|
// Make sure the class isn't whitespace, otherwise it throws exceptions
|
|
if (cssClass.trim() !== '') renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
|
|
});
|
|
}
|
|
|
|
this.id = (++loadingIds);
|
|
}
|
|
|
|
ngOnInit() {
|
|
// If no spinner was passed in loading options we need to fall back
|
|
// to the loadingSpinner in the app's config, then the mode spinner
|
|
if (isUndefined(this.d.spinner)) {
|
|
this.d.spinner = this._config.get('loadingSpinner', this._config.get('spinner', 'ios'));
|
|
}
|
|
|
|
// If the user passed hide to the spinner we don't want to show it
|
|
this.showSpinner = isDefined(this.d.spinner) && this.d.spinner !== 'hide';
|
|
}
|
|
|
|
ionViewWillEnter() {
|
|
this.gestureBlocker.block();
|
|
}
|
|
|
|
ionViewDidLeave() {
|
|
this.gestureBlocker.unblock();
|
|
}
|
|
|
|
ionViewDidEnter() {
|
|
this._plt.focusOutActiveElement();
|
|
|
|
// If there is a duration, dismiss after that amount of time
|
|
if ( this.d && this.d.duration ) {
|
|
this.durationTimeout = setTimeout(() => this.dismiss('backdrop'), this.d.duration);
|
|
}
|
|
|
|
}
|
|
|
|
dismiss(role: any): Promise<any> {
|
|
if (this.durationTimeout) {
|
|
clearTimeout(this.durationTimeout);
|
|
}
|
|
return this._viewCtrl.dismiss(null, role);
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
assert(this.gestureBlocker.blocked === false, 'gesture blocker must be already unblocked');
|
|
this.gestureBlocker.destroy();
|
|
}
|
|
}
|
|
|
|
let loadingIds = -1;
|