From c929dad2e930b809feda07ffbb4c4c2a0ef59335 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sun, 22 Apr 2018 17:01:29 +0200 Subject: [PATCH] fix(angular): adds missing events --- angular/src/providers/platform.ts | 36 ++++++++++++++++++++++++++++++- angular/src/util/util.ts | 6 ++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/angular/src/providers/platform.ts b/angular/src/providers/platform.ts index c452df0324..84b700ec05 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 a0eecf59e2..b279afeb61 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);