[iOS] Fix margin on Shell TitleView (#13319) fixes #13310 fixes #13306

* Fix margin on Shell.TitleView

* - fix ui test
This commit is contained in:
Shane Neuville 2021-01-15 04:50:08 -06:00 коммит произвёл GitHub
Родитель 2fa7165a99
Коммит 4438439991
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 53 добавлений и 24 удалений

Просмотреть файл

@ -1,5 +1,6 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;
#if UITEST
@ -15,6 +16,7 @@ namespace Xamarin.Forms.Controls.Issues
#if UITEST
[NUnit.Framework.Category(UITestCategories.Shell)]
[NUnit.Framework.Category(UITestCategories.TitleView)]
[NUnit.Framework.Category(UITestCategories.UwpIgnore)]
#endif
public class ShellTitleView : TestShell
{
@ -27,6 +29,7 @@ namespace Xamarin.Forms.Controls.Issues
ContentPage createContentPage(string titleView)
{
Label safeArea = new Label();
ContentPage page = new ContentPage()
{
Content = new StackLayout()
@ -35,8 +38,10 @@ namespace Xamarin.Forms.Controls.Issues
{
new Label()
{
Text = "Click through the tabs and make sure title view changes and doesn't duplicate"
}
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
}
}
};
@ -58,7 +63,19 @@ namespace Xamarin.Forms.Controls.Issues
}
#if UITEST && (__IOS__ || __ANDROID__)
#if UITEST
[Test]
public void TitleViewPositionsCorrectly()
{
var titleView = RunningApp.WaitForElement("TitleViewId")[0].Rect;
var topTab = RunningApp.WaitForElement("page 2")[0].Rect;
var titleViewBottom = titleView.Y + titleView.Height;
var topTabTop = topTab.Y;
Assert.GreaterOrEqual(topTabTop, titleViewBottom, "Title View is incorrectly positioned behind tabs");
}
[Test]
public void NoDuplicateTitleViews()

Просмотреть файл

@ -93,7 +93,7 @@ namespace Xamarin.Forms.Platform.iOS
}
if (header != null)
_headerView = new UIContainerView(((IShellController)_shellContext.Shell).FlyoutHeader);
_headerView = new ShellFlyoutHeaderContainer(((IShellController)_shellContext.Shell).FlyoutHeader);
else
_headerView = null;

Просмотреть файл

@ -0,0 +1,28 @@
using System;
namespace Xamarin.Forms.Platform.iOS
{
internal class ShellFlyoutHeaderContainer : UIContainerView
{
public ShellFlyoutHeaderContainer(View view) : base(view)
{
}
public override Thickness Margin
{
get
{
if (!View.IsSet(View.MarginProperty))
{
var newMargin = new Thickness(0, (float)Platform.SafeAreaInsetsForWindow.Top, 0, 0);
if (newMargin != View.Margin)
{
View.Margin = newMargin;
}
}
return View.Margin;
}
}
}
}

Просмотреть файл

@ -22,11 +22,7 @@ namespace Xamarin.Forms.Platform.iOS
ClipsToBounds = true;
view.MeasureInvalidated += OnMeasureInvalidated;
MeasuredHeight = double.NaN;
_view.BatchCommitted += _view_BatchCommitted;
}
private void _view_BatchCommitted(object sender, Internals.EventArg<VisualElement> e)
{
Margin = new Thickness(0);
}
internal View View => _view;
@ -46,22 +42,9 @@ namespace Xamarin.Forms.Platform.iOS
return false;
}
public Thickness Margin
public virtual Thickness Margin
{
get
{
if(!_view.IsSet(View.MarginProperty))
{
var newMargin = new Thickness(0, (float)Platform.SafeAreaInsetsForWindow.Top, 0, 0);
if (newMargin != _view.Margin)
{
_view.Margin = newMargin;
}
}
return _view.Margin;
}
get;
}
void ReMeasure()

Просмотреть файл

@ -278,6 +278,7 @@
<Compile Include="CollectionView\ILoopItemsViewSource.cs" />
<Compile Include="Renderers\IDisconnectable.cs" />
<Compile Include="Extensions\BrushExtensions.shared.cs" />
<Compile Include="Renderers\ShellFlyoutHeaderContainer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\StringResources.ar.resx" />