diff --git a/src/components/action-sheet/action-sheet-component.ts b/src/components/action-sheet/action-sheet-component.ts index d45526cfa0..7de66952c8 100644 --- a/src/components/action-sheet/action-sheet-component.ts +++ b/src/components/action-sheet/action-sheet-component.ts @@ -1,5 +1,6 @@ import { Component, ElementRef, HostListener, Renderer, ViewEncapsulation } from '@angular/core'; +import { ActionSheetOptions, ActionSheetButton } from './action-sheet-options'; import { assert } from '../../util/util'; import { BlockerDelegate, GestureController, BLOCK_ALL } from '../../gestures/gesture-controller'; import { Config } from '../../config/config'; @@ -26,10 +27,10 @@ import { ViewController } from '../../navigation/view-controller'; '{{b.text}}' + '' + '' + - '
' + - '' + '
' + '' + @@ -41,15 +42,11 @@ import { ViewController } from '../../navigation/view-controller'; }, encapsulation: ViewEncapsulation.None, }) + export class ActionSheetCmp { - d: { - title?: string; - subTitle?: string; - cssClass?: string; - buttons?: Array; - enableBackdropDismiss?: boolean; - cancelButton: any; - }; + + d: ActionSheetOptions; + cancelButton: ActionSheetButton; descId: string; enabled: boolean; hdrId: string; @@ -89,30 +86,26 @@ export class ActionSheetCmp { ionViewDidLoad() { // normalize the data - let buttons: any[] = []; - - this.d.buttons.forEach((button: any) => { + this.d.buttons = this.d.buttons.map(button => { if (typeof button === 'string') { button = { text: button }; } if (!button.cssClass) { button.cssClass = ''; } - - if (button.role === 'cancel') { - this.d.cancelButton = button; - - } else { - if (button.role === 'destructive') { + switch (button.role) { + case 'cancel': + this.cancelButton = button; + return null; + case 'destructive': button.cssClass = (button.cssClass + ' ' || '') + 'action-sheet-destructive'; - } else if (button.role === 'selected') { + break; + case 'selected': button.cssClass = (button.cssClass + ' ' || '') + 'action-sheet-selected'; - } - buttons.push(button); + break; } - }); - - this.d.buttons = buttons; + return button; + }).filter(button => button !== null); } ionViewWillEnter() { @@ -141,7 +134,7 @@ export class ActionSheetCmp { } } - click(button: any) { + click(button: ActionSheetButton) { if (!this.enabled) { return; } @@ -163,8 +156,8 @@ export class ActionSheetCmp { bdClick() { if (this.enabled && this.d.enableBackdropDismiss) { - if (this.d.cancelButton) { - this.click(this.d.cancelButton); + if (this.cancelButton) { + this.click(this.cancelButton); } else { this.dismiss('backdrop'); @@ -172,7 +165,7 @@ export class ActionSheetCmp { } } - dismiss(role: any): Promise { + dismiss(role: string): Promise { const opts: NavOptions = { minClickBlockDuration: 400 }; @@ -181,7 +174,7 @@ export class ActionSheetCmp { ngOnDestroy() { assert(this.gestureBlocker.blocked === false, 'gesture blocker must be already unblocked'); - this.d = null; + this.d = this.cancelButton = null; this.gestureBlocker.destroy(); } } diff --git a/src/components/action-sheet/action-sheet-options.ts b/src/components/action-sheet/action-sheet-options.ts index 669367262e..6ff277df9a 100644 --- a/src/components/action-sheet/action-sheet-options.ts +++ b/src/components/action-sheet/action-sheet-options.ts @@ -3,6 +3,14 @@ export interface ActionSheetOptions { title?: string; subTitle?: string; cssClass?: string; - buttons?: Array; + buttons?: (ActionSheetButton|string)[]; enableBackdropDismiss?: boolean; } + +export interface ActionSheetButton { + text?: string; + role?: string; + icon?: string; + cssClass?: string; + handler?: () => boolean|void; +}; diff --git a/src/components/action-sheet/action-sheet.ts b/src/components/action-sheet/action-sheet.ts index 39a0ccf2a5..cb54c5cec0 100644 --- a/src/components/action-sheet/action-sheet.ts +++ b/src/components/action-sheet/action-sheet.ts @@ -1,5 +1,5 @@ import { ActionSheetCmp } from './action-sheet-component'; -import { ActionSheetOptions } from './action-sheet-options'; +import { ActionSheetOptions, ActionSheetButton } from './action-sheet-options'; import { ActionSheetSlideIn, ActionSheetMdSlideIn, ActionSheetSlideOut, ActionSheetMdSlideOut, ActionSheetWpSlideIn, ActionSheetWpSlideOut } from './action-sheet-transitions'; import { App } from '../app/app'; import { Config } from '../../config/config'; @@ -34,7 +34,7 @@ export class ActionSheet extends ViewController { * @hidden */ getTransitionName(direction: string): string { - let key = 'actionSheet' + (direction === 'back' ? 'Leave' : 'Enter'); + const key = 'actionSheet' + (direction === 'back' ? 'Leave' : 'Enter'); return this._nav && this._nav.config.get(key); } @@ -57,7 +57,7 @@ export class ActionSheet extends ViewController { /** * @param {object} button Action sheet button */ - addButton(button: any): ActionSheet { + addButton(button: ActionSheetButton|string): ActionSheet { this.data.buttons.push(button); return this; } diff --git a/src/components/alert/alert-component.ts b/src/components/alert/alert-component.ts index 756e2c6b5b..7fde84ad97 100644 --- a/src/components/alert/alert-component.ts +++ b/src/components/alert/alert-component.ts @@ -295,7 +295,7 @@ export class AlertCmp { } } - dismiss(role: any): Promise { + dismiss(role: string): Promise { const opts: NavOptions = { minClickBlockDuration: 400 }; diff --git a/src/components/alert/test/basic/pages/page-one/page-one.ts b/src/components/alert/test/basic/pages/page-one/page-one.ts index 815b8328de..f111cecef4 100644 --- a/src/components/alert/test/basic/pages/page-one/page-one.ts +++ b/src/components/alert/test/basic/pages/page-one/page-one.ts @@ -158,7 +158,7 @@ export class PageOne { this.testPromptOpen = true; }); - alert.onDidDismiss((data: any, role: any) => { + alert.onDidDismiss((data, role) => { console.log('onDidDismiss, data:', data, 'role:', role); }); } diff --git a/src/components/loading/loading-component.ts b/src/components/loading/loading-component.ts index 5b088a9069..714839dde4 100644 --- a/src/components/loading/loading-component.ts +++ b/src/components/loading/loading-component.ts @@ -87,7 +87,7 @@ export class LoadingCmp { } - dismiss(role: any): Promise { + dismiss(role: string): Promise { if (this.durationTimeout) { clearTimeout(this.durationTimeout); } diff --git a/src/components/picker/picker-component.ts b/src/components/picker/picker-component.ts index 6207f1b900..3bafcf4b49 100644 --- a/src/components/picker/picker-component.ts +++ b/src/components/picker/picker-component.ts @@ -205,7 +205,7 @@ export class PickerCmp { } } - dismiss(role: any): Promise { + dismiss(role: string): Promise { return this._viewCtrl.dismiss(this.getSelected(), role); } diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 469a6e056a..3a306d985f 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -370,7 +370,7 @@ export class Select extends BaseInput implements OnDestroy { this._fireFocus(); - overlay.onDidDismiss((value: any, role: string) => { + overlay.onDidDismiss(() => { this._fireBlur(); this._overlay = undefined; }); @@ -381,7 +381,7 @@ export class Select extends BaseInput implements OnDestroy { /** * Close the select interface. */ - close() { + close(): Promise { if (!this._overlay || !this.isFocus()) { return; } diff --git a/src/components/toast/toast-component.ts b/src/components/toast/toast-component.ts index f03e688609..ad867a2955 100644 --- a/src/components/toast/toast-component.ts +++ b/src/components/toast/toast-component.ts @@ -96,7 +96,7 @@ export class ToastCmp implements AfterViewInit { } } - dismiss(role: any): Promise { + dismiss(role: string): Promise { clearTimeout(this.dismissTimeout); this.dismissTimeout = undefined; return this._viewCtrl.dismiss(null, role, {disableApp: false}); diff --git a/src/navigation/overlay-proxy.ts b/src/navigation/overlay-proxy.ts index 61f7198996..1122305f97 100644 --- a/src/navigation/overlay-proxy.ts +++ b/src/navigation/overlay-proxy.ts @@ -42,7 +42,7 @@ export class OverlayProxy { } } - dismiss(data?: any, role?: any, navOptions?: NavOptions): Promise { + dismiss(data?: any, role?: string, navOptions?: NavOptions): Promise { if (this.overlay) { return this.overlay.dismiss(); } diff --git a/src/navigation/overlay.ts b/src/navigation/overlay.ts index 4c782516bf..8194389ae6 100644 --- a/src/navigation/overlay.ts +++ b/src/navigation/overlay.ts @@ -2,7 +2,7 @@ import { NavOptions } from './nav-util'; export interface Overlay { present(opts?: NavOptions): Promise; - dismiss(data?: any, role?: any, navOptions?: NavOptions): Promise; + dismiss(data?: any, role?: string, navOptions?: NavOptions): Promise; onDidDismiss(callback: Function): void; onWillDismiss(callback: Function): void; } diff --git a/src/navigation/view-controller.ts b/src/navigation/view-controller.ts index 7e1775b4e5..caa1909fca 100644 --- a/src/navigation/view-controller.ts +++ b/src/navigation/view-controller.ts @@ -167,7 +167,7 @@ export class ViewController { * @param {NavOptions} NavOptions Options for the dismiss navigation. * @returns {any} data Returns the data passed in, if any. */ - dismiss(data?: any, role?: any, navOptions: NavOptions = {}): Promise { + dismiss(data?: any, role?: string, navOptions: NavOptions = {}): Promise { if (!this._nav) { assert(this._state === STATE_DESTROYED, 'ViewController does not have a valid _nav'); return Promise.resolve(false); diff --git a/src/util/mock-providers.ts b/src/util/mock-providers.ts index 62320cde56..75357c5f75 100644 --- a/src/util/mock-providers.ts +++ b/src/util/mock-providers.ts @@ -591,7 +591,7 @@ export function mockNgModuleLoader(): NgModuleLoader { export function mockOverlay() { return { present: (opts?: NavOptions) => { return Promise.resolve(); }, - dismiss: (data?: any, role?: any, navOptions?: NavOptions) => { return Promise.resolve(); }, + dismiss: (data?: any, role?: string, navOptions?: NavOptions) => { return Promise.resolve(); }, onDidDismiss: (callback: Function) => { }, onWillDismiss: (callback: Function) => { } };