Fix disappearing MasterDetail menu on UWP (#5808)
authorMatt Lacey <matt@mrlacey.co.uk>
Sat, 1 Jun 2019 01:43:55 +0000 (02:43 +0100)
committerSamantha Houts <samhouts@users.noreply.github.com>
Sat, 1 Jun 2019 01:43:55 +0000 (18:43 -0700)
* 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 <matt@mrlacey.co.uk>
fixes #5412
fixes #5637

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5412.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.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 (file)
index 0000000..3f21e52
--- /dev/null
@@ -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))
+                                       },
+                               }
+                       };
+               }
+       }
+}
index b8fd729..f593183 100644 (file)
@@ -9,6 +9,7 @@
     <Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
   </PropertyGroup>
   <ItemGroup>
+    <Compile Include="$(MSBuildThisFileDirectory)Issue5412.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Helpers\GarbageCollectionHelper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4879.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5555.cs" />
index 84f72ca..8e3bfe8 100644 (file)
@@ -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()