summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52318.cs55
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FragmentContainer.cs31
3 files changed, 75 insertions, 12 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52318.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52318.cs
new file mode 100644
index 00000000..8d86565c
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52318.cs
@@ -0,0 +1,55 @@
+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
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 83a5995b..ef469ec0 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -173,6 +173,7 @@
<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" />
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