8000 feat: importable $closeModal helper (#1088) · CatchABus/nativescript-vue@04199a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04199a5

Browse files
authored
feat: importable $closeModal helper (nativescript-vue#1088)
1 parent 83a82cf commit 04199a5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export { ELEMENT_REF, createNativeView } from './runtimeHelpers';
4040

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

4646
// creates a special root container that calls resetRoot whenever it's children change

src/plugins/modals.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function resolveModalTarget(
6161
return false;
6262
}
6363

64+
const modalStack = [];
65+
6466
export async function $showModal<T = any, P = any>(
6567
component: Component<P>,
6668
options: ShowModalOptions<P, T> = {},
@@ -127,6 +129,9 @@ export async function $showModal<T = any, P = any>(
127129
});
128130
};
129131
const closeModal = (...args: any[]) => {
132+
// remove view from modalStack
133+
modalStack.splice(modalStack.indexOf(view), 1);
134+
130135
view.nativeView?.closeModal(...args);
131136
};
132137

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

145150
view.mount(root);
146151
openModal();
152+
modalStack.push(view);
147153
});
148154
}
155+
156+
export function $closeModal(...args) {
157+
const view = modalStack.at(-1);
158+
159+
view?.context.config.globalProperties.$closeModal(...args);
160+
}

0 commit comments

Comments
 (0)
0