diff --git a/angular/src/providers/platform.ts b/angular/src/providers/platform.ts index c452df03245..84b700ec05e 100644 --- a/angular/src/providers/platform.ts +++ b/angular/src/providers/platform.ts @@ -1,6 +1,7 @@ import { PlatformConfig } from '@ionic/core'; -import { Injectable } from '@angular/core'; +import { EventEmitter, Injectable } from '@angular/core'; +import { proxyEvent } from '../util/util'; @Injectable() export class Platform { @@ -8,7 +9,40 @@ export class Platform { private _platforms: PlatformConfig[] = []; private _readyPromise: Promise; + /** + * @hidden + */ + backButton = new EventEmitter(); + + /** + * The pause event emits when the native platform puts the application + * into the background, typically when the user switches to a different + * application. This event would emit when a Cordova app is put into + * the background, however, it would not fire on a standard web browser. + */ + pause = new EventEmitter(); + + /** + * The resume event emits when the native platform pulls the application + * out from the background. This event would emit when a Cordova app comes + * out from the background, however, it would not fire on a standard web browser. + */ + resume = new EventEmitter(); + + /** + * The resize event emits when the browser window has changed dimensions. This + * could be from a browser window being physically resized, or from a device + * changing orientation. + */ + resize = new EventEmitter(); + constructor() { + + proxyEvent(this.pause, document, 'pause'); + proxyEvent(this.resume, document, 'resume'); + proxyEvent(this.backButton, document, 'backbutton'); + proxyEvent(this.resize, document, 'resize'); + let readyResolve: Function; this._readyPromise = new Promise(res => { readyResolve = res; } ); if ((window as any)['cordova']) { diff --git a/angular/src/util/util.ts b/angular/src/util/util.ts index a0eecf59e23..b279afeb61e 100644 --- a/angular/src/util/util.ts +++ b/angular/src/util/util.ts @@ -8,6 +8,12 @@ export function inputs(instance: any, el: ElementRef, props: string[]) { }); } +export function proxyEvent(emitter: any, el: Node, eventName: string) { + el.addEventListener(eventName, (ev) => { + emitter.emit(ev); + }); +} + export function proxyMethod(ctrlName: string, methodName: string, ...args: any[]) { const controller = ensureElementInBody(ctrlName);