diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2017-03-14 06:57:32 -0500 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-03-14 11:57:32 +0000 |
commit | 9fb7101760535cf108441ab5ff13fe6951cf259e (patch) | |
tree | 3f541b60e3b872801e9b1d6a1102a2db2ae39eee /Xamarin.Forms.Platform.Android | |
parent | 83fd2751e6939eb76a4ecd8b098144afaa2d289f (diff) | |
download | xamarin-forms-9fb7101760535cf108441ab5ff13fe6951cf259e.tar.gz xamarin-forms-9fb7101760535cf108441ab5ff13fe6951cf259e.tar.bz2 xamarin-forms-9fb7101760535cf108441ab5ff13fe6951cf259e.zip |
Fix MasterDetailPage event cycle (#754)
sample code
add tag
change message
changes
changes 2
changes 3
changes 4
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs b/Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs index 432fcd39..6cc493a1 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs @@ -120,28 +120,35 @@ namespace Xamarin.Forms.Platform.Android.AppCompat public override void OnPause() { - var shouldSendEvent = Application.Current.OnThisPlatform().GetSendDisappearingEventOnPause(); + bool shouldSendEvent = Application.Current.OnThisPlatform().GetSendDisappearingEventOnPause(); if (shouldSendEvent) - { - Page currentPage = (Application.Current.MainPage as IPageContainer<Page>)?.CurrentPage; - if (currentPage == null || currentPage == PageController) - PageController?.SendDisappearing(); - } + SendLifecycleEvent(false); base.OnPause(); } public override void OnResume() { - var shouldSendEvent = Application.Current.OnThisPlatform().GetSendAppearingEventOnResume(); + bool shouldSendEvent = Application.Current.OnThisPlatform().GetSendAppearingEventOnResume(); if (shouldSendEvent) - { - Page currentPage = (Application.Current.MainPage as IPageContainer<Page>)?.CurrentPage; - if (UserVisibleHint && (currentPage == null || currentPage == PageController)) - PageController?.SendAppearing(); - } + SendLifecycleEvent(true); base.OnResume(); } + + void SendLifecycleEvent(bool isAppearing) + { + var masterDetailPage = Application.Current.MainPage as MasterDetailPage; + var pageContainer = (masterDetailPage != null ? masterDetailPage.Detail : Application.Current.MainPage) as IPageContainer<Page>; + Page currentPage = pageContainer?.CurrentPage; + + if(!(currentPage == null || currentPage == PageController)) + return; + + if (isAppearing && UserVisibleHint) + PageController?.SendAppearing(); + else if(!isAppearing) + PageController?.SendDisappearing(); + } } }
\ No newline at end of file |