Skip to content

Commit

Permalink
fix(angular): backButton event uses ionBackButton
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Oct 2, 2018
1 parent 657c2ed commit 0337c7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions angular/src/providers/platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter, Injectable } from '@angular/core';
import { Platforms, getPlatforms, isPlatform } from '@ionic/core';
import { BackButtonDetail, Platforms, getPlatforms, isPlatform } from '@ionic/core';
import { proxyEvent } from '../util/util';


Expand All @@ -11,34 +11,34 @@ export class Platform {
/**
* @hidden
*/
backButton = new EventEmitter<Event>();
backButton = new EventEmitter<BackButtonDetail>();

/**
* 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>();
pause = new EventEmitter<void>();

/**
* 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>();
resume = new EventEmitter<void>();

/**
* 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>();
resize = new EventEmitter<void>();

constructor() {
proxyEvent(this.pause, document, 'pause');
proxyEvent(this.resume, document, 'resume');
proxyEvent(this.backButton, document, 'backbutton');
proxyEvent(this.backButton, document, 'ionBackButton');
proxyEvent(this.resize, window, 'resize');

let readyResolve: (value: string) => void;
Expand Down
6 changes: 3 additions & 3 deletions angular/src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementRef } from '@angular/core';
import { ElementRef, EventEmitter } from '@angular/core';

export function inputs(instance: any, el: ElementRef, props: string[]) {
props.forEach(propName => {
Expand All @@ -8,9 +8,9 @@ export function inputs(instance: any, el: ElementRef, props: string[]) {
});
}

export function proxyEvent(emitter: any, el: EventTarget, eventName: string) {
export function proxyEvent<T>(emitter: EventEmitter<T>, el: EventTarget, eventName: string) {
el.addEventListener(eventName, (ev) => {
emitter.emit(ev);
emitter.emit((ev as any).detail as T);
});
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export type ComponentTags = keyof StencilIntrinsicElements;
export type ComponentRef = Function | HTMLElement | string | null;
export type ComponentProps<T = null> = T extends ComponentTags ? StencilIntrinsicElements[T] : {[key: string]: any};
export type CssClassMap = { [className: string]: boolean };
export type BackButtonEvent = CustomEvent<{
export interface BackButtonDetail {
register(priority: number, handler: () => Promise<any> | void): void;
}>
}

export type BackButtonEvent = CustomEvent<BackButtonDetail>;

export interface FrameworkDelegate {
attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise<HTMLElement>;
Expand Down

0 comments on commit 0337c7f

Please sign in to comment.