@@ -215,11 +215,11 @@ In the `Detail` component, add a button that triggers the globally exposed `$nav
215
215
```
216
216
217
217
## Modal View Navigation
218
+ Navigation using modals - detached from the current backstack.
218
219
219
- Use ` $showModal ` to show the ` Detail ` page modally. This function behaves similarly to ` $navigateTo ` .
220
-
221
- To close the modal, call ` $modal.close ` .
220
+ ### Showing a modal
222
221
222
+ Use ` $showModal ` to show the ` Detail ` page modally. This function behaves similarly to ` $navigateTo ` .
223
223
224
224
``` vue
225
225
//Master.vue
@@ -251,51 +251,92 @@ function showDetailPageModally(){
251
251
<Page>
252
252
<ActionBar title="Detail" />
253
253
<StackLayout>
254
- <Button @tap="$modal.close" text="Close " />
254
+ <Label text="I am a modal! " />
255
255
</StackLayout>
256
256
</Page>
257
257
</Frame>
258
258
</template>
259
259
```
260
260
261
-
262
261
Note: We've wrapped the Detail page in a ` <Frame> ` element, which allows us to show the ` <ActionBar> ` as well as navigate further within the modal.
263
262
264
- ### Passing props to the modal
263
+ #### Passing props to the modal
265
264
266
265
` $showModal ` accepts a second parameter. You can use the parameter to pass in a ` props ` object to the target component. For example:
267
266
268
267
``` JavaScript
269
268
$showModal (Detail, { props: { id: 14 }});
270
269
```
271
270
272
- ### Forcing the modal to be fullscreen
271
+ #### Forcing the modal to be fullscreen
273
272
274
273
This option only takes effect on Android, as iOS modals are always fullscreen.
275
274
276
275
``` JavaScript
277
276
$showModal (Detail, { fullscreen: true , props: { id: 14 }});
278
277
```
279
278
280
- ### Returning data from the modal
279
+ ### Closing a modal
280
+
281
+ To close a modal we can close it from the modal template using ` $modal.close() ` or using the ` $closeModal ` function.
282
+
283
+ #### Close modal from modal template
284
+
285
+ ``` vue
286
+ <!-- inside Detail.vue -->
287
+ <Button @tap="$modal.close()" text="Close" />
288
+ ```
289
+
290
+ #### Close modal using ` $closeModal `
291
+
292
+ You can use the ` $closeModal() ` function from anywhere in your application, calling this function will close the last opened modal.
293
+
294
+ ``` vue
295
+ <script lang="ts" setup>
296
+ import { $closeModal } from "nativescript-vue"
297
+
298
+ function closeModal(){
299
+ $closeModal();
300
+ }
301
+ </script>
302
+ <template>
303
+ <Button @tap="closeModal" text="Close" />
304
+ </template>
305
+ ```
306
+
307
+ #### Returning data from the modal
281
308
282
- When calling ` $showModal ` , a promise is returned which resolves with any data passed to the ` $modal.close ` function .
309
+ When calling ` $showModal ` , a promise is returned which resolves with any data passed to the ` $modal.close ` or ` $closeModal ` functions .
283
310
284
311
In the following example, closing the modal outputs 'Foo' in the console.
285
312
286
313
``` JavaScript
287
314
// ... inside Master
288
315
$showModal (Detail, {
289
316
closeCallback (data , ... args ) {
290
- // data type is any
291
- // args type is any[]
317
+ console .log (data); // print: Foo
292
318
}
293
319
});
294
320
```
295
321
296
- ``` HTML
297
- <!-- inside Detail -->
322
+ Examples:
323
+ <br >
324
+ Using ` $modal.close ` .
325
+ ``` vue
326
+ <!-- inside Detail.vue -->
298
327
<Button @tap="$modal.close('Foo')" text="Close" />
299
328
```
300
329
330
+ Using ` $closeModal ` .
331
+ ``` vue
332
+ <script lang="ts" setup>
333
+ import { $closeModal } from "nativescript-vue"
301
334
335
+ function closeModal(){
336
+ $closeModal("Foo");
337
+ }
338
+ </script>
339
+ <template>
340
+ <Button @tap="closeModal" text="Close" />
341
+ </template>
342
+ ```
0 commit comments