mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
@ -1,5 +1,5 @@
|
|||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Inject, Injectable, NgZone } from '@angular/core';
|
||||||
import { BackButtonEventDetail, Platforms, getPlatforms, isPlatform } from '@ionic/core';
|
import { BackButtonEventDetail, Platforms, getPlatforms, isPlatform } from '@ionic/core';
|
||||||
import { Subject, Subscription } from 'rxjs';
|
import { Subject, Subscription } from 'rxjs';
|
||||||
|
|
||||||
@ -42,29 +42,30 @@ export class Platform {
|
|||||||
*/
|
*/
|
||||||
resize = new Subject<void>();
|
resize = new Subject<void>();
|
||||||
|
|
||||||
constructor(@Inject(DOCUMENT) private doc: any) {
|
constructor(@Inject(DOCUMENT) private doc: any, zone: NgZone) {
|
||||||
this.win = doc.defaultView;
|
zone.run(() => {
|
||||||
|
this.win = doc.defaultView;
|
||||||
|
this.backButton.subscribeWithPriority = function(priority, callback) {
|
||||||
|
return this.subscribe(ev => {
|
||||||
|
ev.register(priority, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.backButton.subscribeWithPriority = function(priority, callback) {
|
proxyEvent(this.pause, doc, 'pause');
|
||||||
return this.subscribe(ev => {
|
proxyEvent(this.resume, doc, 'resume');
|
||||||
ev.register(priority, callback);
|
proxyEvent(this.backButton, doc, 'ionBackButton');
|
||||||
});
|
proxyEvent(this.resize, this.win, 'resize');
|
||||||
};
|
|
||||||
|
|
||||||
proxyEvent(this.pause, doc, 'pause');
|
let readyResolve: (value: string) => void;
|
||||||
proxyEvent(this.resume, doc, 'resume');
|
this._readyPromise = new Promise(res => { readyResolve = res; });
|
||||||
proxyEvent(this.backButton, doc, 'ionBackButton');
|
if (this.win && this.win['cordova']) {
|
||||||
proxyEvent(this.resize, this.win, 'resize');
|
doc.addEventListener('deviceready', () => {
|
||||||
|
readyResolve('cordova');
|
||||||
let readyResolve: (value: string) => void;
|
}, { once: true });
|
||||||
this._readyPromise = new Promise(res => { readyResolve = res; });
|
} else {
|
||||||
if (this.win && this.win['cordova']) {
|
readyResolve!('dom');
|
||||||
doc.addEventListener('deviceready', () => {
|
}
|
||||||
readyResolve('cordova');
|
});
|
||||||
}, { once: true });
|
|
||||||
} else {
|
|
||||||
readyResolve!('dom');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,9 @@ describe('providers', () => {
|
|||||||
|
|
||||||
expect(await element(by.css('#is-loaded')).getText()).toEqual('true');
|
expect(await element(by.css('#is-loaded')).getText()).toEqual('true');
|
||||||
expect(await element(by.css('#is-ready')).getText()).toEqual('true');
|
expect(await element(by.css('#is-ready')).getText()).toEqual('true');
|
||||||
|
expect(await element(by.css('#is-paused')).getText()).toEqual('true');
|
||||||
|
expect(await element(by.css('#is-resumed')).getText()).toEqual('true');
|
||||||
|
expect(await element(by.css('#is-resized')).getText()).toEqual('true');
|
||||||
expect(await element(by.css('#is-testing')).getText()).toEqual('false');
|
expect(await element(by.css('#is-testing')).getText()).toEqual('false');
|
||||||
expect(await element(by.css('#is-desktop')).getText()).toEqual('true');
|
expect(await element(by.css('#is-desktop')).getText()).toEqual('true');
|
||||||
expect(await element(by.css('#is-mobile')).getText()).toEqual('false');
|
expect(await element(by.css('#is-mobile')).getText()).toEqual('false');
|
||||||
|
@ -12,6 +12,15 @@
|
|||||||
<p>
|
<p>
|
||||||
isReady: <span id="is-ready">{{isReady}}</span>
|
isReady: <span id="is-ready">{{isReady}}</span>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
isResumed: <span id="is-resumed">{{isResumed}}</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
isPaused: <span id="is-paused">{{isPaused}}</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
isResized: <span id="is-resized">{{isResized}}</span>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
isTesting: <span id="is-testing">{{isTesting}}</span>
|
isTesting: <span id="is-testing">{{isTesting}}</span>
|
||||||
</p>
|
</p>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, NgZone } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
Platform, ModalController, AlertController, ActionSheetController,
|
Platform, ModalController, AlertController, ActionSheetController,
|
||||||
PopoverController, ToastController, Events, PickerController, MenuController,
|
PopoverController, ToastController, Events, PickerController, MenuController,
|
||||||
@ -14,6 +14,9 @@ export class ProvidersComponent {
|
|||||||
isLoaded = false;
|
isLoaded = false;
|
||||||
isReady = false;
|
isReady = false;
|
||||||
isEvent = false;
|
isEvent = false;
|
||||||
|
isResumed = false;
|
||||||
|
isPaused = false;
|
||||||
|
isResized = false;
|
||||||
isTesting: boolean = undefined;
|
isTesting: boolean = undefined;
|
||||||
isDesktop: boolean = undefined;
|
isDesktop: boolean = undefined;
|
||||||
isMobile: boolean = undefined;
|
isMobile: boolean = undefined;
|
||||||
@ -32,7 +35,8 @@ export class ProvidersComponent {
|
|||||||
toastCtrl: ToastController,
|
toastCtrl: ToastController,
|
||||||
navCtrl: NavController,
|
navCtrl: NavController,
|
||||||
domCtrl: DomController,
|
domCtrl: DomController,
|
||||||
config: Config
|
config: Config,
|
||||||
|
zone: NgZone
|
||||||
) {
|
) {
|
||||||
// test all providers load
|
// test all providers load
|
||||||
if (
|
if (
|
||||||
@ -44,15 +48,31 @@ export class ProvidersComponent {
|
|||||||
|
|
||||||
// test platform ready()
|
// test platform ready()
|
||||||
platform.ready().then(() => {
|
platform.ready().then(() => {
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
this.isReady = true;
|
this.isReady = true;
|
||||||
});
|
});
|
||||||
|
platform.resume.subscribe(() => {
|
||||||
|
console.log('platform:resume');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isResumed = true;
|
||||||
|
});
|
||||||
|
platform.pause.subscribe(() => {
|
||||||
|
console.log('platform:pause');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isPaused = true;
|
||||||
|
});
|
||||||
|
platform.resize.subscribe(() => {
|
||||||
|
console.log('platform:resize');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isResized = true;
|
||||||
|
});
|
||||||
this.isDesktop = platform.is('desktop');
|
this.isDesktop = platform.is('desktop');
|
||||||
this.isMobile = platform.is('mobile');
|
this.isMobile = platform.is('mobile');
|
||||||
|
|
||||||
// test events
|
// test events
|
||||||
events.subscribe('topic', () => {
|
events.subscribe('topic', () => {
|
||||||
this.isEvent = true;
|
this.isEvent = true;
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
});
|
});
|
||||||
events.publish('topic');
|
events.publish('topic');
|
||||||
|
|
||||||
@ -60,5 +80,11 @@ export class ProvidersComponent {
|
|||||||
this.isTesting = config.getBoolean('_testing');
|
this.isTesting = config.getBoolean('_testing');
|
||||||
config.set('keyboardHeight', 12345);
|
config.set('keyboardHeight', 12345);
|
||||||
this.keyboardHeight = config.getNumber('keyboardHeight');
|
this.keyboardHeight = config.getNumber('keyboardHeight');
|
||||||
|
|
||||||
|
zone.runOutsideAngular(() => {
|
||||||
|
document.dispatchEvent(new CustomEvent('pause'));
|
||||||
|
document.dispatchEvent(new CustomEvent('resume'));
|
||||||
|
window.dispatchEvent(new CustomEvent('resize'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user