Modal View
Use the showModal
method of the View
class to show another view as a modal dialog. You must specify the location of the modal page module. You can provide a context and a callback function that will be called when the modal view is closed. You can also optionally specify whether to show the modal view in fullscreen or not. To close the modal view, you need to subscribe to its shownModally
event and store a reference to a close callback function provided by the event arguments. Call this function when you are ready to close the modal view, optionally passing some results to the master page. Here is an example with two views — the main view and a login view. The main one shows the login view modally; the user enters their username and password and when ready clicks the Login button. This closes the modal login view and returns the username/password to the main page which can then log the user in.
TIP: By design on iPhone, a modal view appears only in fullscreen.
Basics
Main view
Modal view
Note: With version 4.0.0 of NativeScript, opening a Modal view from another Modal view is officially supported. The previous versions of NativeScript supported only a single Modal view.
Custom Actionbar
With NativeScript version 4.0.0, we can also show custom ActionBar in the modal view. To do that, we should declare a root frame and to set up our default modal view.
Main page
Modal root
Modal view
Modal Navigation
With NativeScript version 4.0.0 and above, we can navigate within a modal view. We need a root frame defaulting to our first modal view. With the Frame
instance, we can navigate within the modal and with the help of closeModal
method, we can close the modal from any View
instance.
Main page
Modal root
First modal view
Second modal view