How does ModalPage force user to not navigate away from a page before completing a task?

mshwfmshwf EGMember ✭✭✭
edited October 2018 in Xamarin.Forms

I read this in docs:

A modal page encourages users to complete a self-contained task that cannot be navigated away from until the task is completed or cancelled.

I can't understand what (programmatically) a modal page can offer other than hiding the navigation bar, I can understand that, from UX perspective, it's better to hide a control (in this case; the back button) if it can lead to unwanted consequences (data-loss), is this really what a modal page about?
and what's the difference between a modal page and a page with no navigation bar:
NavigationPage.HasNavigationBar="False"
as it seems better to use than a modal page that requires different APIs (PushModalAsync ..etc)

Also Why can't I PushAsync() from a modal page? what's the problem of navigating to a normal page from a modal page?

Best Answer

  • LandLuLandLu Xamurai
    Accepted Answer

    @mshwf As the documentation says the modal page just encourages user to do that. Since the default style doesn't contain a back button, it will make user feel that he needs to finish this task on current modal page before he can move on.
    But what you choose is your choice. You can hide the navigation bar when you use the push method, so that it looks like a modal page. The only difference is the appearing animation. Forms just provides you a default style, you can use it or customize it as what you want.
    But please pay attention that if you want to use PushAsync() to display a new page, you must make sure current page has been wrapped by a navigationPage. This method makes several pages placed in a navigation stack, you can push and pop them as you want.
    PushModalAsync() doesn't need that stack, the new page just covers over the previous page. So you can make other effects, for example the new page may be translucent that user can see the previous page covered under the new page.
    Moreover if you want to use PushAsync() from a modal page, you need to modal a navigation page:
    Navigation.PushModalAsync(new NavigationPage(new NewPage()));
    Then this new page could use PushAsync().

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    HIt the back button on the device. Is that honored? If not, then more is happening that just hiding the nav bar.

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    @mshwf As the documentation says the modal page just encourages user to do that. Since the default style doesn't contain a back button, it will make user feel that he needs to finish this task on current modal page before he can move on.
    But what you choose is your choice. You can hide the navigation bar when you use the push method, so that it looks like a modal page. The only difference is the appearing animation. Forms just provides you a default style, you can use it or customize it as what you want.
    But please pay attention that if you want to use PushAsync() to display a new page, you must make sure current page has been wrapped by a navigationPage. This method makes several pages placed in a navigation stack, you can push and pop them as you want.
    PushModalAsync() doesn't need that stack, the new page just covers over the previous page. So you can make other effects, for example the new page may be translucent that user can see the previous page covered under the new page.
    Moreover if you want to use PushAsync() from a modal page, you need to modal a navigation page:
    Navigation.PushModalAsync(new NavigationPage(new NewPage()));
    Then this new page could use PushAsync().

Sign In or Register to comment.