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

Don't set the width of the TitleView to the width of the status bar #14290

Merged
merged 4 commits into from
Jun 2, 2021
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
Expand Up @@ -21,12 +21,69 @@ namespace Xamarin.Forms.Controls.Issues
public class ShellTitleView : TestShell
{
protected override void Init()
{
SetupMeasuringTest1();
SetupMeasuringTest2();
SetupMeasuringTest3();
}

void SetupMeasuringTest3()
{
ContentPage contentPage = new ContentPage();
AddFlyoutItem(contentPage, "Width Measure and ToolBarItem (13949)");

Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.AddChild(new Label() { Text = "Text" }, 0, 0);
grid.AddChild(new Button() { Text = "B1" }, 1, 0);
grid.AddChild(new Button() { Text = "B2" }, 2, 0);

Shell.SetTitleView(contentPage, grid);

contentPage.Content = new StackLayout()
{
Children =
{
new Label() { Text = "TitleView should have one label and two buttons"}
}
};

contentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Item" });
}

void SetupMeasuringTest2()
{
ContentPage contentPage = new ContentPage();
AddFlyoutItem(contentPage, "Width Measure (13949)");

Grid grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.AddChild(new Label() { Text = "Text" }, 0, 0);
grid.AddChild(new Button() { Text = "B1" }, 1, 0);
grid.AddChild(new Button() { Text = "B2" }, 2, 0);

Shell.SetTitleView(contentPage, grid);

contentPage.Content = new StackLayout()
{
Children =
{
new Label() { Text = "TitleView should have one label and two buttons"}
}
};
}

void SetupMeasuringTest1()
{
AddTopTab(createContentPage("title 1"), "page 1");
AddTopTab(createContentPage(null), "page 2");
AddTopTab(createContentPage("title 3"), "page 3");
AddTopTab(createContentPage("title 4"), "page 4");

Items[0].Title = "Duplicate Test";
ContentPage createContentPage(string titleView)
{
Label safeArea = new Label();
Expand All @@ -38,7 +95,7 @@ ContentPage createContentPage(string titleView)
{
new Label()
{
Text = "Tab 1,3, and 4 should have a single visible TitleView. If the TitleView is duplicated or not visible the test has failed.",
Text = "Tab 1, 3, and 4 should have a single visible TitleView. If the TitleView is duplicated or not visible the test has failed.",
AutomationId = "Instructions"
},
safeArea
Expand All @@ -60,11 +117,29 @@ ContentPage createContentPage(string titleView)

return page;
}
}

}

#if UITEST

[Test]
public void TitleWidthMeasuresCorrectly_13949()
{
this.TapInFlyout("Width Measure (13949)");
RunningApp.WaitForElement("Text");
RunningApp.WaitForElement("B1");
RunningApp.WaitForElement("B2");
}

[Test]
public void TitleWidthWithToolBarItemMeasuresCorrectly_13949()
{
this.TapInFlyout("Width Measure and ToolBarItem (13949)");
RunningApp.WaitForElement("Text");
RunningApp.WaitForElement("B1");
RunningApp.WaitForElement("B2");
}

[Test]
public void TitleViewPositionsCorrectly()
{
Expand Down
22 changes: 10 additions & 12 deletions Xamarin.Forms.Platform.iOS/Renderers/ShellPageRendererTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,6 @@ protected virtual void UpdateTitleView()
else
{
var view = new TitleViewContainer(titleView);

if (Forms.IsiOS11OrNewer)
{
view.TranslatesAutoresizingMaskIntoConstraints = false;
}
else
{
view.TranslatesAutoresizingMaskIntoConstraints = true;
view.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
}

NavigationItem.TitleView = view;
}
}
Expand Down Expand Up @@ -399,6 +388,16 @@ public class TitleViewContainer : UIContainerView
public TitleViewContainer(View view) : base(view)
{
MatchHeight = true;

if (Forms.IsiOS11OrNewer)
{
TranslatesAutoresizingMaskIntoConstraints = false;
}
else
{
TranslatesAutoresizingMaskIntoConstraints = true;
AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
}
}

public override CGRect Frame
Expand All @@ -424,7 +423,6 @@ public override void WillMoveToSuperview(UIView newSuper)
Frame = new CGRect(Frame.X, newSuper.Bounds.Y, Frame.Width, newSuper.Bounds.Height);

Height = newSuper.Bounds.Height;
Width = newSuper.Bounds.Width;
}

base.WillMoveToSuperview(newSuper);
Expand Down