From a0fcf30bc3e6c0a544a06328d3c01df85805dc62 Mon Sep 17 00:00:00 2001 From: Matt Lacey Date: Sat, 1 Jun 2019 02:43:55 +0100 Subject: [PATCH] Fix disappearing MasterDetail menu on UWP (#5808) * Ensure Mstrdetail Popover menu is always visible For #5412 * Add UITest for Issue 5412 * Add missing namespace * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs Co-Authored-By: mrlacey fixes #5412 fixes #5637 --- .../Issue5412.cs | 123 +++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + .../MasterDetailPageRenderer.cs | 2 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs new file mode 100644 index 0000000..3f21e52 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using NUnit.Framework; +using Xamarin.UITest; +using Xamarin.UITest.iOS; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(Core.UITests.UITestCategories.MasterDetailPage)] + [Category(Core.UITests.UITestCategories.Navigation)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 5412, "5412 - (NavigationBar disappears on MasterDetailPage)", PlatformAffected.UWP)] + public class Issue5412 : TestContentPage + { + protected override async void Init() + { + await Navigation.PushModalAsync(new Issue5412MainPage()); + } + +#if UITEST && __WINDOWS__ + [Test] + public void Issue5412Test() + { + var hamburgerText = "\uE700"; + var settings = "Settings"; + var back = "Back"; + + RunningApp.WaitForElement(hamburgerText); + RunningApp.Tap(hamburgerText); + + RunningApp.WaitForElement(settings); + RunningApp.Tap(settings); + + RunningApp.WaitForElement(back); + RunningApp.Tap(back); + + // This fails if the menu isn't displayed (original error behavior) + RunningApp.WaitForElement(hamburgerText); + } +#endif + } + + public class Issue5412MainPage : MasterDetailPage + { + public Issue5412MainPage() + { + var menuBtn = new Button + { + Text = "Settings" + }; + menuBtn.Clicked += (sender, e) => + { + var mdp = ((sender as Button).Parent.Parent as MasterDetailPage); + mdp.Detail.Navigation.PushAsync(new Issue5412SettingPage()); + mdp.IsPresented = false; + }; + + MasterBehavior = MasterBehavior.Popover; + Master = new ContentPage + { + Content = menuBtn, + Title = "Menu title" + }; + Detail = new NavigationPage(new Issue5412IndexPage()); + } + } + + public class Issue5412SettingPage : ContentPage + { + public Issue5412SettingPage() + { + Content = new StackLayout + { + HorizontalOptions = LayoutOptions.CenterAndExpand, + VerticalOptions = LayoutOptions.CenterAndExpand, + Children = { + new Label + { + Text = "Settings Page", + FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)) + }, + new Label + { + Text = "Navigate back and check the navbar & menu are still visible.", + FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)) + }, + } + }; + } + }; + + public class Issue5412IndexPage : ContentPage + { + public Issue5412IndexPage() + { + Content = new StackLayout + { + HorizontalOptions = LayoutOptions.CenterAndExpand, + VerticalOptions = LayoutOptions.CenterAndExpand, + Children = { + new Label + { + Text = "Index Page", + FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)) + }, + new Label + { + Text = "Open the hamburger menu and navigate to settings page", + FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)) + }, + } + }; + } + } +} 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 b8fd729..f593183 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 @@ -9,6 +9,7 @@ Xamarin.Forms.Controls.Issues + diff --git a/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs b/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs index 84f72ca..8e3bfe8 100644 --- a/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs @@ -335,7 +335,7 @@ namespace Xamarin.Forms.Platform.UWP return; Control.DetailTitle = GetCurrentPage().Title ?? Element?.Title; - (this as ITitleProvider).ShowTitle = !string.IsNullOrEmpty(Control.DetailTitle); + (this as ITitleProvider).ShowTitle = !string.IsNullOrEmpty(Control.DetailTitle) || Element.MasterBehavior == MasterBehavior.Popover; } async void UpdateDetailTitleIcon() -- 2.7.4