Set MinimumWidth to the correct value on grid calc (#7318)
authorShane Neuville <shneuvil@microsoft.com>
Mon, 21 Oct 2019 19:50:47 +0000 (13:50 -0600)
committerSamantha Houts <samhouts@users.noreply.github.com>
Mon, 21 Oct 2019 19:50:47 +0000 (12:50 -0700)
fixes #7303

Xamarin.Forms.Core.UnitTests/GridTests.cs
Xamarin.Forms.Core/GridCalc.cs

index ed9a6a0..ad40598 100644 (file)
@@ -1541,6 +1541,115 @@ namespace Xamarin.Forms.Core.UnitTests
                }
 
 
+               [Test]
+               public void MinimumWidthRequestInAutoCells()
+               {
+                       var boxRow0Column0 = new BoxView
+                       {
+                               MinimumWidthRequest = 50,
+                               WidthRequest = 200,
+                               IsPlatformEnabled = true
+                       };
+                       var boxRow1Column0 = new BoxView
+                       {
+                               MinimumWidthRequest = 50,
+                               WidthRequest = 200,
+                               IsPlatformEnabled = true
+                       };
+
+                       var boxRow0Column1 = new BoxView
+                       {
+                               WidthRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+                       var boxRow1Column1 = new BoxView
+                       {
+                               WidthRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+
+                       var grid = new Grid
+                       {
+                               IsPlatformEnabled = true,
+                               BackgroundColor = Color.Red
+                       };
+
+                       grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
+                       grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
+
+                       grid.Children.Add(boxRow0Column0, 0, 0);
+                       grid.Children.Add(boxRow1Column0, 0, 1);
+                       grid.Children.Add(boxRow1Column1, 1, 1);
+                       grid.Children.Add(boxRow0Column1, 1, 0);
+
+                       var view = new ContentView
+                       {
+                               IsPlatformEnabled = true,
+                               Content = grid,
+                       };
+                       view.Layout(new Rectangle(0, 0, 800, 800));
+
+
+                       Assert.AreEqual(boxRow0Column0.MinimumWidthRequest, boxRow0Column0.Width);
+                       Assert.AreEqual(boxRow1Column0.MinimumWidthRequest, boxRow1Column0.Width);
+               }
+
+
+               [Test]
+               public void MinimumHeightRequestInAutoCells()
+               {
+                       var boxRow0Column0 = new BoxView
+                       {
+                               MinimumHeightRequest = 50,
+                               HeightRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+                       var boxRow1Column0 = new BoxView
+                       {
+                               HeightRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+
+                       var boxRow0Column1 = new BoxView
+                       {
+                               MinimumHeightRequest = 50,
+                               HeightRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+                       var boxRow1Column1 = new BoxView
+                       {
+                               HeightRequest = 800,
+                               IsPlatformEnabled = true
+                       };
+
+                       var grid = new Grid
+                       {
+                               IsPlatformEnabled = true,
+                               BackgroundColor = Color.Red
+                       };
+
+                       grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
+                       grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
+
+                       grid.Children.Add(boxRow0Column0, 0, 0);
+                       grid.Children.Add(boxRow1Column0, 0, 1);
+                       grid.Children.Add(boxRow1Column1, 1, 1);
+                       grid.Children.Add(boxRow0Column1, 1, 0);
+
+                       var view = new ContentView
+                       {
+                               IsPlatformEnabled = true,
+                               Content = grid,
+                       };
+                       view.Layout(new Rectangle(0, 0, 800, 800));
+
+
+                       Assert.AreEqual(boxRow0Column0.MinimumHeightRequest, boxRow0Column0.Height);
+                       Assert.AreEqual(boxRow0Column1.MinimumHeightRequest, boxRow0Column1.Height);
+               }
+
+
+
                // because the constraint is internal, we need this
                public enum HackLayoutConstraint
                {
index 1f8deab..da108c2 100644 (file)
@@ -170,7 +170,7 @@ namespace Xamarin.Forms
                                                if (actualWidth >= 0)
                                                        col.ActualWidth = actualWidth;
                                                if (minimumWidth >= 0)
-                                                       col.MinimumWidth = actualWidth;
+                                                       col.MinimumWidth = minimumWidth;
                                        }
                                }
                        }