--- /dev/null
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 52318, "OnAppearing/Disappearing triggers for all pages in navigationstack backgrounding/foregrounding app", PlatformAffected.Android)]
+ public class Bugzilla52318 : TestMasterDetailPage // or TestMasterDetailPage, etc ...
+ {
+ protected override void Init()
+ {
+ Master = new ContentPage { Title = "Master page", Content = new Label { Text = "Master page" } };
+ Detail = new NavigationPage(new ContentPage52318());
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class ContentPage52318 : ContentPage
+ {
+ public ContentPage52318()
+ {
+ var stackLayout = new StackLayout();
+ var label = new Label
+ {
+ Text = "Tap on the Navigate button as many times as you like to add to the navigation stack. An alert should be visible on page appearing. Hit the Home button and come back. Only the last page should alert."
+ };
+ stackLayout.Children.Add(label);
+
+ var button = new Button
+ {
+ Text = "Navigate to a new page",
+ Command = new Command(async () =>
+ {
+ await Navigation.PushAsync(new ContentPage52318());
+ })
+ };
+ stackLayout.Children.Add(button);
+
+ Content = stackLayout;
+ }
+
+ protected override void OnAppearing()
+ {
+ int count = (Parent as NavigationPage).Navigation.NavigationStack.Count;
+ Title = $"Page: {count}";
+ DisplayAlert("", Title + " appearing.", "OK");
+ base.OnAppearing();
+ }
+ }
+}
\ No newline at end of file
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47923.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla48236.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla52318.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37290.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51553.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51802.cs" />
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