Skip to content

Commit 5f12f6f

Browse files
committed
feat: documented $closeModal funciont to Routing page
1 parent 1957d8b commit 5f12f6f

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

content/docs/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Thank you for your interest in contributing to NativeScript-Vue!
1111
Follow these steps to start contributing to the NativeScript-Vue codebase:
1212

1313
### Setup
14-
Clone the repository to your local environment:
14+
Clone the [repository](https://github.com/nativescript-vue/nativescript-vue) to your local environment:
1515

1616
```bash
1717
git clone https://github.com/nativescript-vue/nativescript-vue.git

content/docs/essentials/routing.md

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ In the `Detail` component, add a button that triggers the globally exposed `$nav
215215
```
216216

217217
## Modal View Navigation
218+
Navigation using modals - detached from the current backstack.
218219

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
222221

222+
Use `$showModal` to show the `Detail` page modally. This function behaves similarly to `$navigateTo`.
223223

224224
```vue
225225
//Master.vue
@@ -251,51 +251,92 @@ function showDetailPageModally(){
251251
<Page>
252252
<ActionBar title="Detail" />
253253
<StackLayout>
254-
<Button @tap="$modal.close" text="Close" />
254+
<Label text="I am a modal!" />
255255
</StackLayout>
256256
</Page>
257257
</Frame>
258258
</template>
259259
```
260260

261-
262261
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.
263262

264-
### Passing props to the modal
263+
#### Passing props to the modal
265264

266265
`$showModal` accepts a second parameter. You can use the parameter to pass in a `props` object to the target component. For example:
267266

268267
```JavaScript
269268
$showModal(Detail, { props: { id: 14 }});
270269
```
271270

272-
### Forcing the modal to be fullscreen
271+
#### Forcing the modal to be fullscreen
273272

274273
This option only takes effect on Android, as iOS modals are always fullscreen.
275274

276275
```JavaScript
277276
$showModal(Detail, { fullscreen: true, props: { id: 14 }});
278277
```
279278

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
281308

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.
283310

284311
In the following example, closing the modal outputs 'Foo' in the console.
285312

286313
```JavaScript
287314
// ... inside Master
288315
$showModal(Detail, {
289316
closeCallback(data, ...args) {
290-
// data type is any
291-
// args type is any[]
317+
console.log(data); // print: Foo
292318
}
293319
});
294320
```
295321

296-
```HTML
297-
<!-- inside Detail -->
322+
Examples:
323+
<br>
324+
Using `$modal.close`.
325+
```vue
326+
<!-- inside Detail.vue -->
298327
<Button @tap="$modal.close('Foo')" text="Close" />
299328
```
300329

330+
Using `$closeModal`.
331+
```vue
332+
<script lang="ts" setup>
333+
import { $closeModal } from "nativescript-vue"
301334
335+
function closeModal(){
336+
$closeModal("Foo");
337+
}
338+
</script>
339+
<template>
340+
<Button @tap="closeModal" text="Close" />
341+
</template>
342+
```

0 commit comments

Comments
 (0)