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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy