Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modals): make showActions work on web and electron #2501

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions core/src/web/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,20 @@ export class ModalsPluginWeb extends WebPlugin implements ModalsPlugin {

async showActions(options: ActionSheetOptions): Promise<ActionSheetResult> {
return new Promise<ActionSheetResult>(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();
});
}
}
Expand Down
35 changes: 4 additions & 31 deletions electron/src/electron/modals.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -53,36 +55,7 @@ export class ModalsPluginElectron extends WebPlugin implements ModalsPlugin {
}

async showActions(options: ActionSheetOptions): Promise<ActionSheetResult> {
return new Promise<ActionSheetResult>(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);
}

}
Expand Down