summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2017-03-22 10:43:17 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-03-22 10:43:17 (GMT)
commitc65a9a8c57d93b0eff38fd8b06223f6a04688c59 (patch)
tree1392a70d29802674f814c3222dd422451cd7ea47 /Xamarin.Forms.Platform.iOS
parent7538350f6d750f5e29d011834cf36a17a1e045e3 (diff)
downloadxamarin-forms-c65a9a8c57d93b0eff38fd8b06223f6a04688c59.zip
xamarin-forms-c65a9a8c57d93b0eff38fd8b06223f6a04688c59.tar.gz
xamarin-forms-c65a9a8c57d93b0eff38fd8b06223f6a04688c59.tar.bz2
[iOS/Win] Label will not unnecessarily expand (#827)
* Add repro for 53362 * [iOS] Label will not unnecessarily expand * [Win] Label will not unnecessarily expand
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs27
1 files changed, 21 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
index b8b81e9..82ceda8 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
@@ -30,16 +30,31 @@ namespace Xamarin.Forms.Platform.MacOS
_perfectSizeValid = true;
}
- if (widthConstraint >= _perfectSize.Request.Width && heightConstraint >= _perfectSize.Request.Height)
+ var widthFits = widthConstraint >= _perfectSize.Request.Width;
+ var heightFits = heightConstraint >= _perfectSize.Request.Height;
+
+ if (widthFits && heightFits)
return _perfectSize;
var result = base.GetDesiredSize(widthConstraint, heightConstraint);
- result.Minimum = new Size(Math.Min(10, result.Request.Width), result.Request.Height);
- if (Element.LineBreakMode != LineBreakMode.NoWrap)
+ var tinyWidth = Math.Min(10, result.Request.Width);
+ result.Minimum = new Size(tinyWidth, result.Request.Height);
+
+ if (widthFits || Element.LineBreakMode == LineBreakMode.NoWrap)
+ return result;
+
+ bool containerIsNotInfinitelyWide = !double.IsInfinity(widthConstraint);
+
+ if (containerIsNotInfinitelyWide)
{
- if (!double.IsInfinity(result.Request.Width) && !double.IsInfinity(widthConstraint))
- if (result.Request.Width > widthConstraint || Element.LineBreakMode == LineBreakMode.WordWrap || Element.LineBreakMode == LineBreakMode.CharacterWrap)
- result.Request = new Size(Math.Max(result.Minimum.Width, widthConstraint), result.Request.Height);
+ bool textCouldHaveWrapped = Element.LineBreakMode == LineBreakMode.WordWrap || Element.LineBreakMode == LineBreakMode.CharacterWrap;
+ bool textExceedsContainer = result.Request.Width > widthConstraint;
+
+ if (textExceedsContainer || textCouldHaveWrapped)
+ {
+ var expandedWidth = Math.Max(tinyWidth, widthConstraint);
+ result.Request = new Size(expandedWidth, result.Request.Height);
+ }
}
return result;