Skip to content

Commit

Permalink
[Housekeeping] Port latest fixes from Xamarin.Forms to .NET MAUI (#11420
Browse files Browse the repository at this point in the history
)

### Description of Change

Port latest fixes from Xamarin.Forms to .NET MAUI.

### Issues Fixed

Fixes #10128
  • Loading branch information
PureWeen committed Mar 9, 2023
2 parents 9fa5f5f + d04831e commit a775a2d
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue13126_2.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13551.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13916.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue15542.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue15565.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonTemplateFromStyle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellSearchHandlerItemSizing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellWithCustomRendererDisabledAnimations.cs" />
Expand Down
79 changes: 79 additions & 0 deletions src/Compatibility/ControlGallery/src/Issues.Shared/Issue15542.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

#if UITEST
using Microsoft.Maui.Controls.Compatibility.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 15542, "[Bug] Shell.TitleView does not render on iOS 16",
PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
[NUnit.Framework.Category(UITestCategories.TitleView)]
#endif
public class Issue15542 : TestShell
{
protected override void Init()
{
AddTopTab(createContentPage("title 1"), "page 1");
AddTopTab(createContentPage("title 2"), "page 2");
AddTopTab(createContentPage("title 3"), "page 3");

static ContentPage createContentPage(string titleView)
{
Label safeArea = new Label();
ContentPage page = new ContentPage()
{
Content = new StackLayout()
{
Children =
{
new Label()
{
Text = "If the TitleView is not visible the test has failed.",
AutomationId = "Instructions"
},
safeArea
}
}
};

if (!string.IsNullOrWhiteSpace(titleView))
{
SetTitleView(page,
new Grid()
{
BackgroundColor = Colors.Red,
AutomationId = "TitleViewId",
Children = { new Label() { Text = titleView, VerticalTextAlignment = TextAlignment.End } }
});
}

return page;
}
}


#if UITEST

[Test]
public void TitleViewHeightDoesntOverflow()
{
var titleView = RunningApp.WaitForElement("TitleViewId")[0].Rect;
var topTab = RunningApp.WaitForElement("page 1")[0].Rect;

var titleViewBottom = titleView.Y + titleView.Height;
var topTabTop = topTab.Y;

Assert.GreaterOrEqual(topTabTop, titleViewBottom, "Title View is incorrectly positioned in iOS 16");
}
#endif

}
}
105 changes: 105 additions & 0 deletions src/Compatibility/ControlGallery/src/Issues.Shared/Issue15565.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Microsoft.Maui.Controls.CustomAttributes;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

#if UITEST
using Microsoft.Maui.Controls.Compatibility.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 15565, "[Bug] Shell TitleView and ToolBarItems rendering strange display on iOS 16",
PlatformAffected.iOS)]
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
[NUnit.Framework.Category(UITestCategories.TitleView)]
#endif
public class Issue15565 : TestShell
{
protected override void Init()
{
AddTopTab(createContentPage("title 1"), "page 1");
AddTopTab(createContentPage("title 2"), "page 2");
AddTopTab(createContentPage("title 3"), "page 3");

static ContentPage createContentPage(string titleView)
{
Label safeArea = new Label();
ContentPage page = new ContentPage()
{
Content = new StackLayout()
{
Children =
{
new Label()
{
Text = "If the TitleView is not visible at the same time as the ToolbarItems, the test has failed.",
AutomationId = "Instructions"
},
safeArea
}
}
};

page.ToolbarItems.Add(new ToolbarItem() { Text = "Item 1" });
page.ToolbarItems.Add(new ToolbarItem() { Text = "Item 2" });

if (!string.IsNullOrWhiteSpace(titleView))
{
SetTitleView(page,
new Grid()
{
BackgroundColor = Colors.Red,
AutomationId = "TitleViewId",
Children = { new Label() { Text = titleView, VerticalTextAlignment = TextAlignment.End } }
});
}

return page;
}
}


#if UITEST

[Test]
public void TitleViewHeightIsNotZero()
{
var titleView = RunningApp.WaitForElement("TitleViewId")[0].Rect;
var topTab = RunningApp.WaitForElement("page 1")[0].Rect;

var titleViewBottom = titleView.Y + titleView.Height;
var topTabTop = topTab.Y;

Assert.GreaterOrEqual(topTabTop, titleViewBottom, "Title View is incorrectly positioned in iOS 16");
}

[Test]
public void ToolbarItemsWithTitleViewAreRendering()
{
RunningApp.WaitForElement("Item 1");
RunningApp.WaitForElement("Item 3");
}

[Test]
public void NoDuplicateTitleViews()
{
var titleView = RunningApp.WaitForElement("TitleViewId");

Assert.AreEqual(1, titleView.Length);

RunningApp.Tap("page 1");
RunningApp.Tap("page 2");
RunningApp.Tap("page 3");

titleView = RunningApp.WaitForElement("TitleViewId");

Assert.AreEqual(1, titleView.Length);
}
#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected virtual void OnPagePropertyChanged(object sender, PropertyChangedEvent
{
SearchHandler = Shell.GetSearchHandler(Page);
}
else if (e.PropertyName == Shell.TitleViewProperty.PropertyName)
else if (e.IsOneOf(Shell.TitleViewProperty, VisualElement.HeightProperty, VisualElement.WidthProperty))
{
UpdateTitleView();
}
Expand Down

0 comments on commit a775a2d

Please sign in to comment.