Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

NavigationPage Push/Pop event sequence different across platforms

$
0
0

I was using the NaviationPage.Popped event to be able to check/determine in a ContentPage.OnDisappearing event whether this was being called as the page was closing (i.e. being popped) or whether a new page was opening (i.e. new page being pushed on top) by noting the NavigationEventArgs.Page object in Popped to compare against in OnDisappearing .. all of which was working fine in Windows Phone however on Android and iOS this wasn't working as expected and debugging further I discovered the sequence of event calling is radically different when pushing/popping pages between the three platforms?!?!

In Windows Phone it occurs as one (well me anyway :)) would expect in that when a page is pushed the NavPage.Pushed event is called, followed by the current page's OnDisappearing event, then the pushed page's OnAppearing event and then the new page is displayed. When popping the NavPage.Popped event is called, followed by the current page's OnDisappearing event, then the previous page's OnAppearing event and then the previous page is displayed.

In Android however when pushing a new page, it's OnAppearing occurs first, the page is then displayed, then the previous page's OnDisappearing event and finally the NavPage.Pushed event at the end. When popping the previous page's OnAppearing event is called and it's then displayed followed by the popped page's OnDisappearing event and then the NavPage.Popped.

With iOS it's different again .. when pushing the new page is displayed straight away followed by the previous page's OnDisappearing, then (!) the new page's OnAppearing and finally the NavPage.Pushed. With popping the previous page immediately displays, followed by the popped page's OnDisappearing then the previous page's OnAppearing and finally the NavPage.Popped.

Apart from totally screwing up my method for determining whether in OnDisappearing event whether a page is being closed (popped) or hidden (another page pushed on top), which I'd be grateful if anyone know another way to determine that?, it seems really odd to me that these critical sequence of events are different across platforms when the .Forms whole point if to provide a consistent interface and logic across platforms.

For reference here's the sequence as discovered which I'd really like to know if it's meant to be this way or if this is a bug?

WP8

Program starts - NavPage => Navigation.PushAsync(new ui_Page1())

NavPage.Pushed()

    Page1.OnAppearing()

    Page1 now current/displayed

Button clicked - Page1 => Navigation.PushAsync(new ui_Page2())

NavPage.Pushed()

    Page1.OnDisappearing()

        Page2.OnAppearing()

        Page2 now current/displayed

Page2 Backkey pressed

NavPage.Popped()

        Page2.OnDisappearing()

    Page1.OnAppearing()

    Page1 now current/displayed

ANDROID

Program starts - NavPage => Navigation.PushAsync(new ui_Page1())

NavPage.Pushed()

    Page1.OnAppearing()

    Page1 now current/displayed

Button clicked - Page1 => Navigation.PushAsync(new ui_Page2())

        Page2.OnAppearing()

        Page2 now current/displayed

    Page1.OnDisappearing()

NavPage.Pushed()

Page2 Backkey pressed

    Page1.OnAppearing()

    Page1 now current/displayed

        Page2.OnDisappearing()

NavPage.Popped()

IOS

Program starts - NavPage => Navigation.PushAsync(new ui_Page1())

NavPage.Pushed()

    Page1 now current/displayed

    Page1.OnAppearing()

Button clicked - Page1 => Navigation.PushAsync(new ui_Page2())

        Page2 now current/displayed

    Page1.OnDisappearing()

        Page2.OnAppearing()

NavPage.Pushed()

Page2 Backkey pressed

    Page1 now current/displayed

        Page2.OnDisappearing()

    Page1.OnAppearing()

NavPage.Popped()

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>