Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix issue using ToolbarItems with TitleView on iOS 16
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz authored and jfversluis committed Nov 15, 2022
1 parent bf55cba commit c57846a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.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 = Color.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 @@ -55,6 +55,7 @@
<DependentUpon>Issue14801.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue15368.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue15565.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8606.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue15066.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8804.xaml.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected virtual void OnPagePropertyChanged(object sender, PropertyChangedEvent
{
SearchHandler = Shell.GetSearchHandler(Page);
}
else if (e.PropertyName == Shell.TitleViewProperty.PropertyName)
else if (e.PropertyName == Shell.TitleViewProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName)
{
UpdateTitleView();
}
Expand Down

0 comments on commit c57846a

Please sign in to comment.