Skip to content

Commit

Permalink
Reinstate IntrinsicContentSize check - the bug this was removed to pr…
Browse files Browse the repository at this point in the history
…event

is fixed by PR #1700.
  • Loading branch information
hartez committed Jul 16, 2021
1 parent bc14913 commit 11f2bab
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Core/src/Platform/iOS/MauiLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public MauiLabel()
public override void DrawText(CGRect rect) =>
base.DrawText(TextInsets.InsetRect(rect));

public override void InvalidateIntrinsicContentSize()
{
base.InvalidateIntrinsicContentSize();

if (Frame.Width == 0 && Frame.Height == 0)
{
// The Label hasn't actually been laid out on screen yet; no reason to request a layout
return;
}

if (!Frame.Size.IsCloseTo(AddInsets(IntrinsicContentSize), (nfloat)0.001))
{
// The text or its attributes have changed enough that the size no longer matches the set Frame. It's possible
// that the Label needs to be laid out again at a different size, so we request that the parent do so.
Superview?.SetNeedsLayout();
}
}

public override CGSize SizeThatFits(CGSize size) => AddInsets(base.SizeThatFits(size));

CGSize AddInsets(CGSize size) => new CGSize(
Expand Down

0 comments on commit 11f2bab

Please sign in to comment.