Skip to content
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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export { ELEMENT_REF, createNativeView } from './runtimeHelpers';

export * from '@vue/runtime-core';
export { vShow } from './directives/vShow';
export { $showModal } from './plugins/modals';
export { $showModal, $closeModal } from './plugins/modals';
export { $navigateTo, $navigateBack } from './plugins/navigation';

// creates a special root container that calls resetRoot whenever it's children change
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function resolveModalTarget(
return false;
}

const modalStack = [];

export async function $showModal<T = any, P = any>(
component: Component<P>,
options: ShowModalOptions<P, T> = {},
Expand Down Expand Up @@ -127,6 +129,9 @@ export async function $showModal<T = any, P = any>(
});
};
const closeModal = (...args: any[]) => {
// remove view from modalStack
modalStack.splice(modalStack.indexOf(view), 1);

view.nativeView?.closeModal(...args);
};

Expand All @@ -144,5 +149,12 @@ export async function $showModal<T = any, P = any>(

view.mount(root);
openModal();
modalStack.push(view);
});
}

export function $closeModal(...args) {
const view = modalStack.at(-1);

view?.context.config.globalProperties.$closeModal(...args);
}