Skip to content

Commit

Permalink
Always add the margin to our measureArrange Size
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-devel709 committed Jun 28, 2024
1 parent 19b31cd commit 3e91a0f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Controls/src/Core/Button/Button.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
+ (nfloat)Math.Max(titleRectWidth, platformButton.CurrentImage?.Size.Width ?? 0)
+ (nfloat)padding.Left
+ (nfloat)padding.Right
+ (nfloat)button.Margin.HorizontalThickness
+ (nfloat)borderWidth * 2;

var buttonContentHeight =
+ (nfloat)Math.Max(titleRectHeight, platformButton.CurrentImage?.Size.Height ?? 0)
+ (nfloat)padding.Top
+ (nfloat)padding.Bottom
+ (nfloat)button.Margin.VerticalThickness
+ (nfloat)borderWidth * 2;

// if we have both an image and title, add the smaller of the two to the calculation as well
Expand All @@ -136,11 +134,15 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
}
}

var ret = new Size(button.WidthRequest == -1 ? Math.Min(buttonContentWidth, buttonWidthConstraint) : button.WidthRequest,
var returnSize = new Size(button.WidthRequest == -1 ? Math.Min(buttonContentWidth, buttonWidthConstraint) : button.WidthRequest,
button.HeightRequest == -1 ? Math.Min(buttonContentHeight, buttonHeightConstraint) : button.HeightRequest);

// Add the margins to the return size
returnSize.Width += (nfloat)button.Margin.HorizontalThickness;
returnSize.Height += (nfloat)button.Margin.VerticalThickness;

// Rounding the values up to the nearest whole number to match UIView.SizeThatFits
return new Size((int)Math.Ceiling(ret.Width), (int)Math.Ceiling(ret.Height));
return new Size((int)Math.Ceiling(returnSize.Width), (int)Math.Ceiling(returnSize.Height));
}

/// <summary>
Expand Down

0 comments on commit 3e91a0f

Please sign in to comment.