summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-06-22 11:49:41 +0200
committerRui Marinho <me@ruimarinho.net>2017-06-22 10:49:41 +0100
commitf6bdb76b0a7803af633b28e7fd2dac1d08b419e5 (patch)
tree62172fa495a4b018740ddc35132f1f350acb390f /Xamarin.Forms.Platform.iOS
parent7e4628e0dd645aae03358b4a74639a2feed64f0d (diff)
downloadxamarin-forms-f6bdb76b0a7803af633b28e7fd2dac1d08b419e5.tar.gz
xamarin-forms-f6bdb76b0a7803af633b28e7fd2dac1d08b419e5.tar.bz2
xamarin-forms-f6bdb76b0a7803af633b28e7fd2dac1d08b419e5.zip
[iOS] decoupling UpdateText() on LabelRenderer (#950)
* [iOS] decoupling UpdateText() on LabelRenderer * [iOS] do not update font and color on formattedstrings
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs67
1 files changed, 52 insertions, 15 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
index 5eef6915..0d016e50 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
@@ -6,12 +6,14 @@ using SizeF = CoreGraphics.CGSize;
#if __MOBILE__
using UIKit;
using NativeLabel = UIKit.UILabel;
-
-namespace Xamarin.Forms.Platform.iOS
#else
using AppKit;
using NativeLabel = AppKit.NSTextField;
+#endif
+#if __MOBILE__
+namespace Xamarin.Forms.Platform.iOS
+#else
namespace Xamarin.Forms.Platform.MacOS
#endif
{
@@ -110,6 +112,9 @@ namespace Xamarin.Forms.Platform.MacOS
}
UpdateText();
+ UpdateTextColor();
+ UpdateFont();
+
UpdateLineBreakMode();
UpdateAlignment();
}
@@ -126,9 +131,9 @@ namespace Xamarin.Forms.Platform.MacOS
else if (e.PropertyName == Label.VerticalTextAlignmentProperty.PropertyName)
UpdateLayout();
else if (e.PropertyName == Label.TextColorProperty.PropertyName)
- UpdateText();
+ UpdateTextColor();
else if (e.PropertyName == Label.FontProperty.PropertyName)
- UpdateText();
+ UpdateFont();
else if (e.PropertyName == Label.TextProperty.PropertyName)
UpdateText();
else if (e.PropertyName == Label.FormattedTextProperty.PropertyName)
@@ -241,6 +246,7 @@ namespace Xamarin.Forms.Platform.MacOS
#endif
}
+ bool isTextFormatted;
void UpdateText()
{
_perfectSizeValid = false;
@@ -251,26 +257,57 @@ namespace Xamarin.Forms.Platform.MacOS
{
#if __MOBILE__
Control.AttributedText = formatted.ToAttributed(Element, (Color)values[2]);
- }
- else
- {
- Control.Text = (string)values[1];
- // default value of color documented to be black in iOS docs
- Control.Font = Element.ToUIFont();
- Control.TextColor = ((Color)values[2]).ToUIColor(ColorExtensions.Black);
- }
#else
Control.AttributedStringValue = formatted.ToAttributed(Element, (Color)values[2]);
+#endif
+ isTextFormatted = true;
}
else
{
+ if (isTextFormatted)
+ {
+ UpdateFont();
+ UpdateTextColor();
+ }
+#if __MOBILE__
+ Control.Text = (string)values[1];
+#else
Control.StringValue = (string)values[1] ?? "";
- // default value of color documented to be black in iOS docs
- Control.Font = Element.ToNSFont();
- Control.TextColor = ((Color)values[2]).ToNSColor(ColorExtensions.Black);
+#endif
+ isTextFormatted = false;
}
+ UpdateLayout();
+ }
+
+ void UpdateFont()
+ {
+ if(isTextFormatted)
+ return;
+ _perfectSizeValid = false;
+
+#if __MOBILE__
+ Control.Font = Element.ToUIFont();
+#else
+ Control.Font = Element.ToNSFont();
#endif
+ UpdateLayout();
+ }
+
+ void UpdateTextColor()
+ {
+ if (isTextFormatted)
+ return;
+
+ _perfectSizeValid = false;
+
+ var textColor = (Color)Element.GetValue(Label.TextColorProperty);
+ // default value of color documented to be black in iOS docs
+#if __MOBILE__
+ Control.TextColor = textColor.ToUIColor(ColorExtensions.Black);
+#else
+ Control.TextColor = textColor.ToNSColor(ColorExtensions.Black);
+#endif
UpdateLayout();
}