Skip to content

Commit

Permalink
fix(angular): adds missing events
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 22, 2018
1 parent 822f60f commit c929dad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 35 additions & 1 deletion angular/src/providers/platform.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@

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 {

private _platforms: PlatformConfig[] = [];
private _readyPromise: Promise<any>;

/**
* @hidden
*/
backButton = new EventEmitter<Event>();

/**
* 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<Event>();

/**
* 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<Event>();

/**
* 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<Event>();

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']) {
Expand Down
6 changes: 6 additions & 0 deletions angular/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c929dad

Please sign in to comment.