From 6c94e6e0c8017a2bfdbff8a719cb310281f0094b Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Mon, 3 Sep 2018 10:36:54 +0100 Subject: [PATCH] =?UTF-8?q?[iOS]=C2=A0Specify=20a=20default=20size=20for?= =?UTF-8?q?=20UISearchBar=20width=20if=20needed=20(#3635)=20fixes=20#3413?= =?UTF-8?q?=20fixes=20#2139?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 --- .../Issue3413.cs | 78 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 3 +- .../Renderers/SearchBarRenderer.cs | 16 +++- 3 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3413.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3413.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3413.cs new file mode 100644 index 000000000..e6c09291f --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue3413.cs @@ -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 + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 578ad02e1..f6c3abb78 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -9,7 +9,7 @@ Xamarin.Forms.Controls.Issues - + @@ -772,6 +772,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs index cfc2a48e5..867abe2cb 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs @@ -129,10 +129,18 @@ namespace Xamarin.Forms.Platform.iOS public override CoreGraphics.CGSize SizeThatFits(CoreGraphics.CGSize size) { - if (nfloat.IsInfinity(size.Width) && Forms.IsiOS11OrNewer) - size.Width = nfloat.MaxValue; - - return base.SizeThatFits(size); + if (nfloat.IsInfinity(size.Width)) + size.Width = (nfloat)(Element?.Parent is VisualElement parent ? parent.Width : Device.Info.ScaledScreenSize.Width); + + 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)