fix(angular): backButton event uses ionBackButton

This commit is contained in:
Manu Mtz.-Almeida
2018-10-02 13:14:37 +02:00
parent 657c2edc4d
commit 0337c7f567
3 changed files with 13 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { EventEmitter, Injectable } from '@angular/core'; 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'; import { proxyEvent } from '../util/util';
@ -11,7 +11,7 @@ export class Platform {
/** /**
* @hidden * @hidden
*/ */
backButton = new EventEmitter<Event>(); backButton = new EventEmitter<BackButtonDetail>();
/** /**
* The pause event emits when the native platform puts the application * The pause event emits when the native platform puts the application
@ -19,26 +19,26 @@ export class Platform {
* application. This event would emit when a Cordova app is put into * application. This event would emit when a Cordova app is put into
* the background, however, it would not fire on a standard web browser. * 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 * 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. This event would emit when a Cordova app comes
* out from the background, however, it would not fire on a standard web browser. * 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 * 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 * could be from a browser window being physically resized, or from a device
* changing orientation. * changing orientation.
*/ */
resize = new EventEmitter<Event>(); resize = new EventEmitter<void>();
constructor() { constructor() {
proxyEvent(this.pause, document, 'pause'); proxyEvent(this.pause, document, 'pause');
proxyEvent(this.resume, document, 'resume'); proxyEvent(this.resume, document, 'resume');
proxyEvent(this.backButton, document, 'backbutton'); proxyEvent(this.backButton, document, 'ionBackButton');
proxyEvent(this.resize, window, 'resize'); proxyEvent(this.resize, window, 'resize');
let readyResolve: (value: string) => void; let readyResolve: (value: string) => void;

View File

@ -1,4 +1,4 @@
import { ElementRef } from '@angular/core'; import { ElementRef, EventEmitter } from '@angular/core';
export function inputs(instance: any, el: ElementRef, props: string[]) { export function inputs(instance: any, el: ElementRef, props: string[]) {
props.forEach(propName => { props.forEach(propName => {
@ -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) => { el.addEventListener(eventName, (ev) => {
emitter.emit(ev); emitter.emit((ev as any).detail as T);
}); });
} }

View File

@ -40,9 +40,11 @@ export type ComponentTags = keyof StencilIntrinsicElements;
export type ComponentRef = Function | HTMLElement | string | null; export type ComponentRef = Function | HTMLElement | string | null;
export type ComponentProps<T = null> = T extends ComponentTags ? StencilIntrinsicElements[T] : {[key: string]: any}; export type ComponentProps<T = null> = T extends ComponentTags ? StencilIntrinsicElements[T] : {[key: string]: any};
export type CssClassMap = { [className: string]: boolean }; export type CssClassMap = { [className: string]: boolean };
export type BackButtonEvent = CustomEvent<{ export interface BackButtonDetail {
register(priority: number, handler: () => Promise<any> | void): void; register(priority: number, handler: () => Promise<any> | void): void;
}> }
export type BackButtonEvent = CustomEvent<BackButtonDetail>;
export interface FrameworkDelegate { export interface FrameworkDelegate {
attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise<HTMLElement>; attachViewToDom(container: any, component: any, propsOrDataObj?: any, cssClasses?: string[]): Promise<HTMLElement>;