Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Scale potential star row/column values by the appropriate star value
Browse files Browse the repository at this point in the history
Along with 13085, this fixes #13127
  • Loading branch information
hartez committed Dec 15, 2020
1 parent 30f29a3 commit 7d43b2c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
41 changes: 41 additions & 0 deletions Xamarin.Forms.Core.UnitTests/GridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,47 @@ public void ContractionAppliedEquallyOnMultiStarRows()
Assert.That(column0Height, Is.EqualTo(column1Height / 2));
}

[Test]
public void Issue13127()
{
var scrollView = new ScrollView() { IsPlatformEnabled = true };
var outerGrid = new Grid() { RowSpacing = 0, IsPlatformEnabled = true };
var outerStackLayout = new StackLayout() { Spacing = 0, IsPlatformEnabled = true };

var innerGrid = new Grid() { RowSpacing = 0, IsPlatformEnabled = true };
innerGrid.RowDefinitions = new RowDefinitionCollection() {
new RowDefinition(){ Height = new GridLength(6, GridUnitType.Star)},
new RowDefinition(){ Height = new GridLength(4, GridUnitType.Star)},
};

// Set up the background view, only covers the first row
var background = new BoxView() { IsPlatformEnabled = true };
Grid.SetRowSpan(background, 1);

// Create the foreground, which spans both rows
var foreground = new StackLayout() { Spacing = 0, IsPlatformEnabled = true };
var view1 = new FixedSizeLabel(new Size(200, 50)) { IsPlatformEnabled = true };
var view2 = new FixedSizeLabel(new Size(200, 100)) { IsPlatformEnabled = true };
foreground.Children.Add(view1);
foreground.Children.Add(view2);
Grid.SetRowSpan(foreground, 2);

innerGrid.Children.Add(background);
innerGrid.Children.Add(foreground);

outerStackLayout.Children.Add(innerGrid);
outerGrid.Children.Add(outerStackLayout);
scrollView.Content = outerGrid;

var sizeRequest = scrollView.Measure(500, 1000);
scrollView.Layout(new Rectangle(0, 0, sizeRequest.Request.Width, 1000));

Assert.That(innerGrid.Height, Is.EqualTo(foreground.Height));
Assert.That(background.Height, Is.EqualTo(foreground.Height * 0.6).Within(0.01));

Assert.That(background.Height, Is.EqualTo(165));
}

abstract class TestLabel : Label
{
protected TestLabel()
Expand Down
8 changes: 4 additions & 4 deletions Xamarin.Forms.Core/GridCalc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ void MeasureAndContractStarredRows(Grid grid, double width, double height, doubl
if (!col.Width.IsStar || col.Width.Value == 0 || col.ActualWidth <= 0)
continue;

starColRequestWidth = Math.Max(starColRequestWidth, col.ActualWidth);
starColMinWidth = Math.Max(starColMinWidth, col.MinimumWidth);
starColRequestWidth = Math.Max(starColRequestWidth, col.ActualWidth / col.Width.Value);
starColMinWidth = Math.Max(starColMinWidth, col.MinimumWidth / col.Width.Value);
}

if (starColRequestWidth * totalStarsWidth <= widthConstraint)
Expand Down Expand Up @@ -750,8 +750,8 @@ void MeasureAndContractStarredRows(Grid grid, double width, double height, doubl
if (!row.Height.IsStar || row.Height.Value == 0 || row.ActualHeight <= 0)
continue;

starRowRequestHeight = Math.Max(starRowRequestHeight, row.ActualHeight);
starRowMinHeight = Math.Max(starRowMinHeight, row.MinimumHeight);
starRowRequestHeight = Math.Max(starRowRequestHeight, row.ActualHeight / row.Height.Value);
starRowMinHeight = Math.Max(starRowMinHeight, row.MinimumHeight / row.Height.Value);
}

if (starRowRequestHeight * totalStarsHeight <= heightConstraint)
Expand Down

0 comments on commit 7d43b2c

Please sign in to comment.