зеркало из https://github.com/DeGsoft/maui-linux.git
Correct Grid Height When Aspect Fit Image Gets Shrinked (#4990)
- fixes #4933 * Grid size incorrect when using with Image #4990 * Unit Test for Grid size incorrect when using with Image #4933 * Grid size incorrect when using with Image #4933 * Unit Test for Grid size incorrect when using with Image #4933
This commit is contained in:
Родитель
5ff83859b8
Коммит
339bd2bc82
|
@ -0,0 +1,32 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 4933, "Grid size incorrect when using with Image", PlatformAffected.All)]
|
||||
public class Issue4493 : TestContentPage // or TestMasterDetailPage, etc ...
|
||||
{
|
||||
protected override void Init()
|
||||
{
|
||||
// Initialize ui here instead of ctor
|
||||
BackgroundColor = Color.Gray;
|
||||
var contentGrid = new Grid
|
||||
{
|
||||
AutomationId = "IssuePageGrid",
|
||||
HorizontalOptions = LayoutOptions.FillAndExpand,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
BackgroundColor = Color.Maroon,
|
||||
RowSpacing = 0,
|
||||
RowDefinitions = new RowDefinitionCollection()
|
||||
{
|
||||
new RowDefinition(){Height = GridLength.Auto},
|
||||
new RowDefinition(){Height = 20}
|
||||
}
|
||||
};
|
||||
contentGrid.AddChild(new Image() { Source = "photo.jpg", AutomationId = "IssuePageImage" }, 0, 0);
|
||||
contentGrid.AddChild(new Label() { Text = "test message", BackgroundColor = Color.Blue }, 0, 1);
|
||||
Content = contentGrid;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -890,6 +890,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue4138.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4314.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue3318.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4493.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5172.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1519,6 +1519,28 @@ namespace Xamarin.Forms.Core.UnitTests
|
|||
Assert.False (invalidated);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
//https://github.com/xamarin/Xamarin.Forms/issues/4933
|
||||
public void GridHeightCorrectWhenAspectFitImageGetsShrinked()
|
||||
{
|
||||
var contentGrid = new Grid
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.FillAndExpand,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
RowDefinitions = new RowDefinitionCollection()
|
||||
{
|
||||
new RowDefinition(){Height = GridLength.Auto}
|
||||
}
|
||||
};
|
||||
//image will have "EVERYTHING IS 100 x 20" size so grid should shrink it and itself to 50x10
|
||||
contentGrid.Children.Add(new Image() { IsPlatformEnabled = true }, 0, 0);
|
||||
var measurement = contentGrid.Measure(50, 100);
|
||||
Assert.AreEqual(50, measurement.Request.Width);
|
||||
Assert.AreEqual(10, measurement.Request.Height);
|
||||
}
|
||||
|
||||
|
||||
// because the constraint is internal, we need this
|
||||
public enum HackLayoutConstraint
|
||||
{
|
||||
|
|
|
@ -374,7 +374,7 @@ namespace Xamarin.Forms
|
|||
void MeasureAndContractStarredColumns(double width, double height, double totalStarsWidth)
|
||||
{
|
||||
double starColWidth;
|
||||
starColWidth = MeasuredStarredColumns();
|
||||
starColWidth = MeasuredStarredColumns(width, height);
|
||||
|
||||
if (!double.IsPositiveInfinity(width) && double.IsPositiveInfinity(height))
|
||||
{
|
||||
|
@ -426,7 +426,7 @@ namespace Xamarin.Forms
|
|||
ContractRowsIfNeeded(height, r => r.Height.IsStar);
|
||||
}
|
||||
|
||||
double MeasuredStarredColumns()
|
||||
double MeasuredStarredColumns(double widthConstraint, double heightConstraint)
|
||||
{
|
||||
double starColWidth;
|
||||
for (var iteration = 0; iteration < 2; iteration++)
|
||||
|
@ -450,7 +450,7 @@ namespace Xamarin.Forms
|
|||
continue;
|
||||
double assignedWidth = GetAssignedColumnWidth(child);
|
||||
|
||||
SizeRequest sizeRequest = child.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins);
|
||||
SizeRequest sizeRequest = child.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins);
|
||||
actualWidth = Math.Max(actualWidth, sizeRequest.Request.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing);
|
||||
minimumWidth = Math.Max(minimumWidth, sizeRequest.Minimum.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче