From 67dfb16f6e88aa9862f9d1b6c58e62777159c5ce Mon Sep 17 00:00:00 2001 From: Pavel Yakovlev Date: Tue, 5 Jun 2018 22:40:40 +0300 Subject: [PATCH] [Core] Fixes '0*' RowDefinition/ColumnDefinition in Grid (#2926) fixes #2767 --- .../Issue2767.cs | 51 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + Xamarin.Forms.Core/GridCalc.cs | 4 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2767.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2767.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2767.cs new file mode 100644 index 000000000..109e05abd --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2767.cs @@ -0,0 +1,51 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2767, "ArgumentException: NaN not valid for height", PlatformAffected.All)] + public class Issue2767 : TestContentPage + { + protected override void Init() + { + var grid = new Grid + { + RowDefinitions = + { + new RowDefinition { Height = new GridLength(0, GridUnitType.Star) }, + new RowDefinition { Height = new GridLength(60, GridUnitType.Star) }, + }, + ColumnDefinitions = + { + new ColumnDefinition { Width = new GridLength(0, GridUnitType.Star) }, + new ColumnDefinition { Width = new GridLength(10, GridUnitType.Star) }, + } + }; + grid.AddChild(new Label { Text = "Collapsed" }, 0, 0); + grid.AddChild(new Label { Text = "Collapsed" }, 0, 1); + grid.AddChild(new Label { Text = "Collapsed" }, 1, 0); + grid.AddChild(new Label { Text = "Label 1:1" }, 1, 1); + + Content = new Frame + { + HorizontalOptions = LayoutOptions.CenterAndExpand, + Content = grid + }; + } + +#if UITEST + [Test] + public void Issue2767Test() + { + RunningApp.WaitForElement("Label 1:1"); + Assert.IsEmpty(RunningApp.Query("Collapsed")); + } +#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 fef04724e..8f296a5c6 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 @@ -239,6 +239,7 @@ + diff --git a/Xamarin.Forms.Core/GridCalc.cs b/Xamarin.Forms.Core/GridCalc.cs index f04e356f5..a47cbf83e 100644 --- a/Xamarin.Forms.Core/GridCalc.cs +++ b/Xamarin.Forms.Core/GridCalc.cs @@ -468,7 +468,7 @@ namespace Xamarin.Forms ColumnDefinition col = _columns[index]; if (!col.Width.IsStar) continue; - starColWidth = Math.Max(starColWidth, col.ActualWidth / col.Width.Value); + starColWidth = col.Width.Value != 0 ? Math.Max(starColWidth, col.ActualWidth / col.Width.Value) : 0; } return starColWidth; @@ -567,7 +567,7 @@ namespace Xamarin.Forms RowDefinition row = _rows[index]; if (!row.Height.IsStar) continue; - starRowHeight = Math.Max(starRowHeight, row.ActualHeight / row.Height.Value); + starRowHeight = row.Height.Value != 0 ? Math.Max(starRowHeight, row.ActualHeight / row.Height.Value) : 0; } return starRowHeight;