diff options
author | Seungkeun Lee <sngn.lee@samsung.com> | 2017-01-24 07:52:46 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-04-24 13:36:51 +0900 |
commit | b7a4bea557677055fc72cde96630a35479e67955 (patch) | |
tree | ef09181f7339fd46aeb7e52dd85485b0126221fa | |
parent | 6ad1d32498bc7bdb05a9b8e2b4067dd6f349f0a8 (diff) | |
download | xamarin-forms-b7a4bea557677055fc72cde96630a35479e67955.tar.gz xamarin-forms-b7a4bea557677055fc72cde96630a35479e67955.tar.bz2 xamarin-forms-b7a4bea557677055fc72cde96630a35479e67955.zip |
Refactoring LabelRenderer
- Optimize update of FormattedText
Change-Id: Iad0b8a4972bfef97f28502d724d443188411f760
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Native/FormattedString.cs | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | Xamarin.Forms.Platform.Tizen/Native/Span.cs | 3 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs | 40 |
3 files changed, 25 insertions, 21 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Native/FormattedString.cs b/Xamarin.Forms.Platform.Tizen/Native/FormattedString.cs index da3d1460..cb93aff9 100644 --- a/Xamarin.Forms.Platform.Tizen/Native/FormattedString.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/FormattedString.cs @@ -92,8 +92,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native } else { - var conStr = string.Concat(from span in this.Spans select span.GetMarkupText()); - return conStr.Replace(Environment.NewLine, "<br>"); + return string.Concat(from span in Spans select span.GetMarkupText()); } } diff --git a/Xamarin.Forms.Platform.Tizen/Native/Span.cs b/Xamarin.Forms.Platform.Tizen/Native/Span.cs index c92fefcf..f0932f4b 100755..100644 --- a/Xamarin.Forms.Platform.Tizen/Native/Span.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/Span.cs @@ -1,3 +1,4 @@ +using System; using System.Text; using EColor = ElmSharp.Color; @@ -272,7 +273,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native { return text.Replace("<", "<") .Replace(">", ">") - .Replace("\n", "<br>"); + .Replace(Environment.NewLine, "<br>"); } public string GetStyle() diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs index 0f723790..1fdd7fba 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs @@ -57,22 +57,15 @@ namespace Xamarin.Forms.Platform.Tizen foreach (var span in formattedString.Spans) { Native.Span nativeSpan = new Native.Span(); - nativeSpan.FormattedText = span.Text; - nativeSpan.FontAttributes = span.FontAttributes == FontAttributes.None ? Element.FontAttributes : span.FontAttributes; - nativeSpan.FontFamily = span.FontFamily == null ? Element.FontFamily : span.FontFamily; - nativeSpan.FontSize = span.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) ? Element.FontSize : span.FontSize; + nativeSpan.Text = span.Text; + nativeSpan.FontAttributes = span.FontAttributes; + nativeSpan.FontFamily = span.FontFamily; + nativeSpan.FontSize = span.FontSize; nativeSpan.LineBreakMode = Control.LineBreakMode; - nativeSpan.HorizontalTextAlignment = Control.HorizontalTextAlignment; + nativeSpan.VerticalTextAlignment = Control.VerticalTextAlignment; + nativeSpan.ForegroundColor = span.ForegroundColor.ToNative(); + nativeSpan.BackgroundColor = span.BackgroundColor.ToNative(); - if (span.ForegroundColor.IsDefault) - nativeSpan.ForegroundColor = Element.TextColor.IsDefault ? s_defaultForegroundColor : Element.TextColor.ToNative(); - else - nativeSpan.ForegroundColor = span.ForegroundColor.ToNative(); - - if (span.BackgroundColor.IsDefault) - nativeSpan.BackgroundColor = Element.BackgroundColor.IsDefault ? s_defaultBackgroundColor : Element.BackgroundColor.ToNative(); - else - nativeSpan.BackgroundColor = span.BackgroundColor.ToNative(); nativeString.Spans.Add(nativeSpan); } @@ -89,14 +82,20 @@ namespace Xamarin.Forms.Platform.Tizen void UpdateTextColor() { Control.TextColor = Element.TextColor.IsDefault ? s_defaultTextColor : Element.TextColor.ToNative(); - UpdateFormattedText(); } void UpdateTextAlignment() { + if (Control.FormattedText != null) + { + foreach (var span in Control.FormattedText.Spans) + { + span.VerticalTextAlignment = Element.VerticalTextAlignment.ToNative(); + } + } + Control.HorizontalTextAlignment = Element.HorizontalTextAlignment.ToNative(); Control.VerticalTextAlignment = Element.VerticalTextAlignment.ToNative(); - UpdateFormattedText(); } void UpdateFontProperties() @@ -104,13 +103,18 @@ namespace Xamarin.Forms.Platform.Tizen Control.FontSize = Element.FontSize; Control.FontAttributes = Element.FontAttributes; Control.FontFamily = Element.FontFamily; - UpdateFormattedText(); } void UpdateLineBreakMode() { + if (Control.FormattedText != null) + { + foreach (var span in Control.FormattedText.Spans) + { + span.LineBreakMode = ConvertToNativeLineBreakMode(Element.LineBreakMode); + } + } Control.LineBreakMode = ConvertToNativeLineBreakMode(Element.LineBreakMode); - UpdateFormattedText(); } Native.LineBreakMode ConvertToNativeLineBreakMode(LineBreakMode mode) |