Page not popped when using NavigationPage with animated navigation

mo_hmo_h USMember

I have a Xamarin Forms application (currently targeting only iOS platform). I have this strange issue where Navigation does not seem to be working correctly when using a Navigation Page with animated navigation and tapping the back button really quickly.

Here is the scenario.

Initialize a Navigation Page with Content Page A.
Navigate from Content Page A to Content Page B using await NavigationPage.PushAsync(Page B, true);
The issue is when the back button is pressed really quickly (i.e. as soon as the animation of Page A -> B finishes or perhaps the animation has not even finished yet??) Page B is not popped off the navigation stack. When navigating to Page B again a second Page B is added to the navigation stack.

Example navigation stack.

Scenario 1 (Back button tapped really quickly i.e. as soon as the navigation animation animation finishes or maybe it is just before the animation even finishes)

Actions: Page A -> Page B -> Back Button (Back to Page A) -> Page B -> Back Button (Back to Page A) -> Page B
Stack: [Page A] -> [Page A, Page B] -> [Page A, Page B] -> [Page A, Page B, Page B] -> [Page A, Page B, Page B] -> [Page A, Page B, Page B, Page B]

Scenario 2 (Back button tapped after waiting a while, i.e. animation fully completes or when using non animated push i.e. await NavigationPage.PushAsync(Page B, false);

Actions: Page A -> Page B -> Back Button (Back to Page A) -> Page B -> Back Button (Back to Page A) -> Page B
Stack: [Page A] -> [Page A, Page B] -> [Page A] -> [Page A, Page B] -> [Page A] -> [Page A, Page B]

I am able to reproduce the issue on both a simulator and physical device (ipad mini) using Xamarin forms 2.5.0.122203. As you can see the correct behaviour occurs in scenario 2 when waiting for the animation to complete or using the pushAsync method with animated=false. (If using pushAsync(Page B, false) i.e. no animation then even scenario 1 is working correctly, the issue is happening only when the navigation is with animation = true and pressing the back button really quickly)

This poses the issue of weird behaviour if the end user for whatever reason taps the back button really quickly after the initial navigation has started. I am unsure if this is a bug in XF or if I am doing something wrong. Why is the NavigationPage.Popped event not triggered if the back button is tapped before the animation completes. If this is the case is there a way to disable the back button until the animation finishes. I can use the non-animated pushAsync as a work around but wold prefer to have the animations active.

Sign In or Register to comment.