Skip to content

Commit

Permalink
fix(images): Images with margin were returning wrong measure size.
Browse files Browse the repository at this point in the history
In situations where the measured size is required in the arranged phase, the measure value was reported without the margins, leading to broken layout in some situations.
  • Loading branch information
carldebilly committed Mar 19, 2020
1 parent c5b700f commit 917cee0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/Image/Image.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
measuredSize = this.AdjustSize(availableSize, measuredSize);
}

measuredSize = measuredSize.LogicalToPhysicalPixels();
var physicalMeasuredSize = measuredSize
.LogicalToPhysicalPixels();

// Report our final dimensions.
SetMeasuredDimension(
(int)measuredSize.Width,
(int)measuredSize.Height
);
var width = (int)physicalMeasuredSize.Width;
var height = (int)physicalMeasuredSize.Height;

IFrameworkElementHelper.OnMeasureOverride(this);
SetMeasuredDimension(width, height);

IFrameworkElementHelper
.SizeThatFits(this, new Size(width, height).PhysicalToLogicalPixels());
}

partial void OnLayoutPartial(bool changed, int left, int top, int right, int bottom)
Expand Down
5 changes: 1 addition & 4 deletions src/Uno.UI/UI/Xaml/Controls/Layouter/Layouter.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ protected Size MeasureChildOverride(View view, Size slotSize)
var ret = Uno.UI.Controls.BindableView.GetNativeMeasuredDimensionsFast(view)
.PhysicalToLogicalPixels();

ret.Width = Math.Min(slotSize.Width, ret.Width);
ret.Height = Math.Min(slotSize.Height, ret.Height);

return ret;
return ret.AtMost(slotSize);
}

protected abstract void MeasureChild(View view, int widthSpec, int heightSpec);
Expand Down

0 comments on commit 917cee0

Please sign in to comment.