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

[iOS 16] Fix wrong size TitleView issue on iOS 16 #15600

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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, 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 = Color.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

}
}
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)Issue15542.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8606.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue15066.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8804.xaml.cs">
Expand Down
10 changes: 10 additions & 0 deletions Xamarin.Forms.Platform.iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static class Forms
static bool? s_isiOS14OrNewer;
static bool? s_isiOS15OrNewer;
static bool? s_isiOS154OrNewer;
static bool? s_isiOS16OrNewer;
static bool? s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden;

internal static bool IsiOS9OrNewer
Expand Down Expand Up @@ -125,6 +126,15 @@ internal static bool IsiOS154OrNewer
}
}

internal static bool IsiOS16OrNewer
{
get
{
if (!s_isiOS16OrNewer.HasValue)
s_isiOS16OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(16, 0);
return s_isiOS16OrNewer.Value;
}
}

internal static bool RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden
{
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