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

Commit 43d5751

Browse files
authored
Scale potential star row/column values by the appropriate star value (#13146) fixes #13127 fixes #13034
Along with 13085, this fixes #13127
1 parent 30f29a3 commit 43d5751

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

Xamarin.Forms.Core.UnitTests/GridTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,47 @@ public void ContractionAppliedEquallyOnMultiStarRows()
591591
Assert.That(column0Height, Is.EqualTo(column1Height / 2));
592592
}
593593

594+
[Test]
595+
public void Issue13127()
596+
{
597+
var scrollView = new ScrollView() { IsPlatformEnabled = true };
598+
var outerGrid = new Grid() { RowSpacing = 0, IsPlatformEnabled = true };
599+
var outerStackLayout = new StackLayout() { Spacing = 0, IsPlatformEnabled = true };
600+
601+
var innerGrid = new Grid() { RowSpacing = 0, IsPlatformEnabled = true };
602+
innerGrid.RowDefinitions = new RowDefinitionCollection() {
603+
new RowDefinition(){ Height = new GridLength(6, GridUnitType.Star)},
604+
new RowDefinition(){ Height = new GridLength(4, GridUnitType.Star)},
605+
};
606+
607+
// Set up the background view, only covers the first row
608+
var background = new BoxView() { IsPlatformEnabled = true };
609+
Grid.SetRowSpan(background, 1);
610+
611+
// Create the foreground, which spans both rows
612+
var foreground = new StackLayout() { Spacing = 0, IsPlatformEnabled = true };
613+
var view1 = new FixedSizeLabel(new Size(200, 50)) { IsPlatformEnabled = true };
614+
var view2 = new FixedSizeLabel(new Size(200, 100)) { IsPlatformEnabled = true };
615+
foreground.Children.Add(view1);
616+
foreground.Children.Add(view2);
617+
Grid.SetRowSpan(foreground, 2);
618+
619+
innerGrid.Children.Add(background);
620+
innerGrid.Children.Add(foreground);
621+
622+
outerStackLayout.Children.Add(innerGrid);
623+
outerGrid.Children.Add(outerStackLayout);
624+
scrollView.Content = outerGrid;
625+
626+
var sizeRequest = scrollView.Measure(500, 1000);
627+
scrollView.Layout(new Rectangle(0, 0, sizeRequest.Request.Width, 1000));
628+
629+
Assert.That(innerGrid.Height, Is.EqualTo(foreground.Height));
630+
Assert.That(background.Height, Is.EqualTo(foreground.Height * 0.6).Within(0.01));
631+
632+
Assert.That(background.Height, Is.EqualTo(165));
633+
}
634+
594635
abstract class TestLabel : Label
595636
{
596637
protected TestLabel()

Xamarin.Forms.Core/GridCalc.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ double MeasuredStarredColumns(Grid grid, double widthConstraint, double heightCo
689689
if (!col.Width.IsStar || col.Width.Value == 0 || col.ActualWidth <= 0)
690690
continue;
691691

692-
starColRequestWidth = Math.Max(starColRequestWidth, col.ActualWidth);
693-
starColMinWidth = Math.Max(starColMinWidth, col.MinimumWidth);
692+
starColRequestWidth = Math.Max(starColRequestWidth, col.ActualWidth / col.Width.Value);
693+
starColMinWidth = Math.Max(starColMinWidth, col.MinimumWidth / col.Width.Value);
694694
}
695695

696696
if (starColRequestWidth * totalStarsWidth <= widthConstraint)
@@ -750,8 +750,8 @@ double MeasureStarredRows(Grid grid, double widthConstraint, double heightConstr
750750
if (!row.Height.IsStar || row.Height.Value == 0 || row.ActualHeight <= 0)
751751
continue;
752752

753-
starRowRequestHeight = Math.Max(starRowRequestHeight, row.ActualHeight);
754-
starRowMinHeight = Math.Max(starRowMinHeight, row.MinimumHeight);
753+
starRowRequestHeight = Math.Max(starRowRequestHeight, row.ActualHeight / row.Height.Value);
754+
starRowMinHeight = Math.Max(starRowMinHeight, row.MinimumHeight / row.Height.Value);
755755
}
756756

757757
if (starRowRequestHeight * totalStarsHeight <= heightConstraint)

0 commit comments

Comments
 (0)