How to prevent overlapping navigation in NavigationPage?

I am currently trying to fix an annoying problem in my Xamarin Forms app (iOS and Android).

Assume a NavigationPage that currently has two pages on the stack:

Page2 (topmost, currently displayed)
Page1

Page2 has a Button "Go to Page3", that binds to a Command which in turn executes the following method:

Task Navigate()
{
    return navigationPage.PushAsync(new Page3(), true);
}

Now what I do is the following:
I tap the "< BACK" button in the navigation bar, and then immediately tap "Go to Page3" before Page2 has a chance to disappear.

This causes Page2 to animate away and Page1 to appear. Then as soon as Page1 has appeared, the app navigates to Page3, leading to the following navigation stack:

Page3 (topmost, currently displayed)
Page1

This is more or less correct from the point of view of the NavigationPage I suppose, but I do not want my app to be able to get into this state.
I would be able to prevent this if there was a way to detect back navigation as soon as it starts, but I can't see how to detect that.

How do you solve this issue?

Answers

  • Patil2421Patil2421 USMember ✭✭✭

    @TomtomFooBar : To overcome you can simply use an activity indicator with an overlay which will cover your whole once you tapped on the back button on your Page 2. This will also indicate something is going on for that fraction of time which it takes to navigate back to Page 1, and due to this overlay overlapping user will not be able to click on GoToPage 3 button until the back button process completes.

  • TomtomFooBarTomtomFooBar GTMember ✭✭

    @TomtomFooBar said:
    I would be able to prevent this if there was a way to detect back navigation as soon as it starts, but I can't see how to detect that.

    Thank you Patil2421, but as I said, I don't know how to detect tapping the back button.

Sign In or Register to comment.