import { EventEmitter , Injectable } from '@angular/core' ; import { ModalController } from '@ionic/angular' ; import { Subscription } from 'rxjs' ; import { ActionSheetComponent } from '../action-sheet/action-sheet.component' ; import { ActionSheetConfig } from '../action-sheet/config/action-sheet-config' ; import { ActionSheetItem } from '../action-sheet/config/action-sheet-item' ; import { Overlay } from './modal.interfaces' ; @ Injectable ( ) export class ActionSheetHelper { constructor ( private ionicModalController ) { } public async showActionSheet ( config ) { const cancel = new EventEmitter ( ) ; const itemSelect = new EventEmitter < ActionSheetItem > ( ) ; const ionModal = await this . ionicModalController . create ( { component : ActionSheetComponent , cssClass : [ 'kirby-overlay' , 'kirby-action-sheet' ] , componentProps : { ... config , cancel : cancel , itemSelect : itemSelect , } , backdropDismiss : true , } ) ; const cancelSubscription = cancel . subscribe ( ( ) => ionModal . dismiss ( ) ) ; const itemSelectSubscription = itemSelect . subscribe ( ( item ) => ionModal . dismiss ( item ) ) ; const onDidDismiss = ionModal . onDidDismiss ( ) ; onDidDismiss . then ( ( _ ) => { cancelSubscription . unsubscribe ( ) ; itemSelectSubscription . unsubscribe ( ) ; } ) ; await ionModal . present ( ) ; return { dismiss : ionModal . dismiss . bind ( ionModal ) , onWillDismiss : ionModal . onWillDismiss ( ) , onDidDismiss : ionModal . onDidDismiss ( ) , } ; } }