You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,67 +4,143 @@ description: Navigation using modals - detached from the current backstack.
4
4
contributos:
5
5
- Ombuweb
6
6
- rigor789
7
+
- flipperlite
7
8
---
8
9
9
10
## Showing a modal
10
11
11
12
To show a modal, call the [showModal](https://docs.nativescript.org/api/class/ViewCommon#showmodal) method on a [View](https://docs.nativescript.org/api/class/View) instance and pass it the path to the modal view file:
12
13
14
+
<!-- note: we need a "Open In StackBlitz" button, and also put these in an official NativeScript collection to link on the docs. -->
15
+
<!-- A strongly typed, working, Typescript application can be [found here](https://stackblitz.com/edit/nativescript-stackblitz-templates-3bvo1g?file=app%2Fdetails-page.ts,app%2Fdetails-page.xml,app%2Fmain-page.ts). -->
If your modal does not appear when tapping the button, confirm you set the correct path and the modal page exists. `showModal` does not throw an error when the provided path doesn't exist.
35
+
:::
36
+
24
37
## Closing a modal
25
38
26
-
To close a modal, call the `closeModal` method of any `View` from the modal. Optionally pass it data you want to access in the parent page:
39
+
To close a modal, call the `closeModal` method of any `View` from the modal.
40
+
41
+
For passing data back to the parent, see [Passing Data](#passing-data).
27
42
28
43
```xml
29
-
<Buttontext="Close"tap="onTap"/>
44
+
<Buttontext="Close a Modal"tap="onCloseModal"/>
30
45
```
31
46
32
47
```ts
33
-
onTap(args: EventData) {
34
-
const button =args.objectasButton
35
-
button.closeModal({
36
-
name: 'John Doe - EDITED',
37
-
})
48
+
exportfunction onCloseModal(args:EventData) {
49
+
const view =args.objectasView
50
+
view.closeModal()
38
51
}
39
52
```
40
53
41
-
## Passing data to and from a modal
54
+
## Passing data {#passing-data}
55
+
56
+
Modals are often used for prompting the user for input, this requires passing data between the parent and the modal.
42
57
43
-
Passing data can be done by passing a `context` in the `showModal` options parameter.
58
+
### From parent to modal
59
+
60
+
To pass data to the modal, provide it in the `context` field of the ShowModalOptions:
0 commit comments