diff --git a/core/src/web/modals.ts b/core/src/web/modals.ts index c8e1d5ee5..5d2da906f 100644 --- a/core/src/web/modals.ts +++ b/core/src/web/modals.ts @@ -41,34 +41,20 @@ export class ModalsPluginWeb extends WebPlugin implements ModalsPlugin { async showActions(options: ActionSheetOptions): Promise { return new Promise(async (resolve, _reject) => { - var controller: any = document.querySelector('ion-action-sheet-controller'); - - if (!controller) { - controller = document.createElement('ion-action-sheet-controller'); - document.body.appendChild(controller); + var actionSheet: any = document.querySelector('pwa-action-sheet'); + if (!actionSheet) { + actionSheet = document.createElement('pwa-action-sheet'); + document.body.appendChild(actionSheet); } - - await controller.componentOnReady(); - - const items = options.options.map((o, i) => { - return { - text: o.title, - role: o.style && o.style.toLowerCase() || '', - icon: o.icon || '', - handler: () => { - resolve({ - index: i - }); - } - }; + actionSheet.header = options.title; + actionSheet.cancelable = false; + actionSheet.options = options.options; + actionSheet.addEventListener('onSelection', async (e: any) => { + const selection = e.detail; + resolve({ + index: selection + }); }); - - const actionSheetElement = await controller.create({ - title: options.title, - buttons: items - }); - - await actionSheetElement.present(); }); } } diff --git a/electron/src/electron/modals.ts b/electron/src/electron/modals.ts index b57c9a428..002ca49de 100644 --- a/electron/src/electron/modals.ts +++ b/electron/src/electron/modals.ts @@ -1,4 +1,6 @@ -import { WebPlugin } from "@capacitor/core"; +import { ModalsPluginWeb, WebPlugin } from "@capacitor/core"; + +const webModals = new ModalsPluginWeb(); const { dialog , getCurrentWindow } = require('electron').remote; @@ -53,36 +55,7 @@ export class ModalsPluginElectron extends WebPlugin implements ModalsPlugin { } async showActions(options: ActionSheetOptions): Promise { - return new Promise(async (resolve, _reject) => { - var controller: any = document.querySelector('ion-action-sheet-controller'); - - if (!controller) { - controller = document.createElement('ion-action-sheet-controller'); - document.body.appendChild(controller); - } - - await controller.componentOnReady(); - - const items = options.options.map((o, i) => { - return { - text: o.title, - role: o.style && o.style.toLowerCase() || '', - icon: o.icon || '', - handler: () => { - resolve({ - index: i - }); - } - }; - }); - - const actionSheetElement = await controller.create({ - title: options.title, - buttons: items - }); - - await actionSheetElement.present(); - }); + return webModals.showActions(options); } }