[iOS] Specify a default size for UISearchBar width if needed (#3635) fixes #3413 fixes #2139

* [Controls] Add reproduction and test case for issue #3413

* [iOS] Don't use max value for iOS UISearchbar breaks on iOS 11.3

* [iOS] Force width value so we can renderer UISearchBar on iOS10 with infinite width

* [Controls] Fix spelling and add Manual Review to the test of #3413

* [iOS] Simplify code for UISearchBar width

* [iOS] Return always some width from measure the UISearchBar on IOS

* [Controls] Add reproduction case for issue #2139
This commit is contained in:
Rui Marinho 2018-09-03 10:36:54 +01:00 коммит произвёл GitHub
Родитель a8260b0075
Коммит 6c94e6e0c8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 92 добавлений и 5 удалений

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

@ -0,0 +1,78 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 3413, "[iOS] Searchbar in Horizontal Stacklayout doesn't render", PlatformAffected.iOS)]
public class Issue3413 : TestContentPage
{
protected override void Init()
{
Padding = new Thickness(20);
var layout = new StackLayout
{
Orientation = StackOrientation.Vertical
};
var searchBar = new SearchBar
{
BackgroundColor = Color.Yellow,
Text = "i m on a vertical stacklayout",
AutomationId = "srb_vertical"
};
layout.Children.Add(new Label { Text = "Vertical" });
layout.Children.Add(searchBar);
var layout1 = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
var searchBar1 = new SearchBar
{
BackgroundColor = Color.Yellow,
Text = "i m on a horizontal stacklayout",
AutomationId = "srb_horizontal"
};
layout1.Children.Add(new Label { Text = "Horizontal" });
layout1.Children.Add(searchBar1);
var searchBar2 = new SearchBar
{
BackgroundColor = Color.Blue,
Text = "i m with expand",
HorizontalOptions = LayoutOptions.CenterAndExpand,
AutomationId = "srb_grid"
};
var grid = new Grid();
grid.Children.Add(layout);
Grid.SetRow(layout, 0);
grid.Children.Add(layout1);
Grid.SetRow(layout1, 1);
grid.Children.Add(searchBar2);
Grid.SetRow(searchBar2, 2);
Content = grid;
}
#if UITEST
[Test]
[Category(UITestCategories.ManualReview)]
public void Issue3413Test ()
{
RunningApp.WaitForElement (q => q.Marked ("srb_vertical"));
RunningApp.WaitForElement (q => q.Marked ("srb_horizontal"));
RunningApp.Screenshot ("Please verify we have 2 SearchBars. One below the label, other side by side with the label");
}
#endif
}
}

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

@ -9,7 +9,7 @@
<Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace> <Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Issue2894.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue2894.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3524.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3524.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2004.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue2004.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3333.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3333.cs" />
@ -772,6 +772,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue2728.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue2728.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1667.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1667.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3012.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3012.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3413.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3525.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3525.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

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

@ -129,10 +129,18 @@ namespace Xamarin.Forms.Platform.iOS
public override CoreGraphics.CGSize SizeThatFits(CoreGraphics.CGSize size) public override CoreGraphics.CGSize SizeThatFits(CoreGraphics.CGSize size)
{ {
if (nfloat.IsInfinity(size.Width) && Forms.IsiOS11OrNewer) if (nfloat.IsInfinity(size.Width))
size.Width = nfloat.MaxValue; size.Width = (nfloat)(Element?.Parent is VisualElement parent ? parent.Width : Device.Info.ScaledScreenSize.Width);
return base.SizeThatFits(size); var sizeThatFits = Control.SizeThatFits(size);
if (Forms.IsiOS11OrNewer)
return sizeThatFits;
////iOS10 hack because SizeThatFits always returns a width of 0
sizeThatFits.Width = (nfloat)Math.Max(sizeThatFits.Width, size.Width);
return sizeThatFits;
} }
void OnCancelClicked(object sender, EventArgs args) void OnCancelClicked(object sender, EventArgs args)