summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>2017-01-16 08:52:05 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-07-10 02:11:28 (GMT)
commit0797bfc37545d5f43741fe63027d72b410d52852 (patch)
tree694796277d4a572d481875f6e8b4a9e6eb8418f4
parent0b87fd361e90937bcf665bab0ecfbe08483da5bf (diff)
downloadxamarin-forms-0797bfc37545d5f43741fe63027d72b410d52852.zip
xamarin-forms-0797bfc37545d5f43741fe63027d72b410d52852.tar.gz
xamarin-forms-0797bfc37545d5f43741fe63027d72b410d52852.tar.bz2
Initialize Label with a single batch update
Change-Id: Id3811e8014accc2044c6422d1fab2381ac4594ed Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs64
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/IBatchable.cs7
-rwxr-xr-xXamarin.Forms.Platform.Tizen/Native/Label.cs12
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs11
4 files changed, 92 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs b/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs
new file mode 100644
index 0000000..5f630e1
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Native/BatchableExtensions.cs
@@ -0,0 +1,64 @@
+´╗┐using System.Runtime.CompilerServices;
+
+namespace Xamarin.Forms.Platform.Tizen.Native
+{
+ internal static class BatchableExtensions
+ {
+ static readonly ConditionalWeakTable<IBatchable, BatchCount> s_counters = new ConditionalWeakTable<IBatchable, BatchCount>();
+
+ public static void BatchBegin(this IBatchable target)
+ {
+ BatchCount value = null;
+
+ if (s_counters.TryGetValue(target, out value))
+ {
+ value.Count++;
+ }
+ else
+ {
+ s_counters.Add(target, new BatchCount());
+ }
+ }
+
+ public static void BatchCommit(this IBatchable target)
+ {
+ BatchCount value = null;
+ if (s_counters.TryGetValue(target, out value))
+ {
+ value.Count--;
+ if (value.Count == 0)
+ {
+ target.OnBatchCommitted();
+ }
+ else if (value.Count < 0)
+ {
+ Log.Error("Called BatchCommit() without BatchBegin().");
+ value.Count = 0;
+ }
+ }
+ else
+ {
+ Log.Error("Called BatchCommit() without BatchBegin().");
+ }
+ }
+
+ public static bool IsBatched(this IBatchable target)
+ {
+ BatchCount value = null;
+
+ if (s_counters.TryGetValue(target, out value))
+ {
+ return value.Count != 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ class BatchCount
+ {
+ public int Count = 1;
+ }
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/IBatchable.cs b/Xamarin.Forms.Platform.Tizen/Native/IBatchable.cs
new file mode 100644
index 0000000..3783596
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Native/IBatchable.cs
@@ -0,0 +1,7 @@
+´╗┐namespace Xamarin.Forms.Platform.Tizen.Native
+{
+ internal interface IBatchable
+ {
+ void OnBatchCommitted();
+ }
+}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/Label.cs b/Xamarin.Forms.Platform.Tizen/Native/Label.cs
index b508b21..3c50073 100755
--- a/Xamarin.Forms.Platform.Tizen/Native/Label.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/Label.cs
@@ -10,7 +10,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// The Label class extends <c>ElmSharp.Label</c> to be better suited for Xamarin renderers.
/// Mainly the formatted text support.
/// </summary>
- public class Label : ELabel, ITextable, IMeasurable
+ public class Label : ELabel, ITextable, IMeasurable, IBatchable
{
/// <summary>
/// The _span holds the content of the label.
@@ -379,9 +379,17 @@ namespace Xamarin.Forms.Platform.Tizen.Native
return formattedSize;
}
+ void IBatchable.OnBatchCommitted()
+ {
+ ApplyTextAndStyle();
+ }
+
void ApplyTextAndStyle()
{
- SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle());
+ if (!this.IsBatched())
+ {
+ SetInternalTextAndStyle(_span.GetDecoratedText(), _span.GetStyle());
+ }
}
void SetInternalTextAndStyle(string formattedText, string textStyle)
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs
index b3701d3..08547c9 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/LabelRenderer.cs
@@ -1,3 +1,4 @@
+using Xamarin.Forms.Platform.Tizen.Native;
using EColor = ElmSharp.Color;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Label;
@@ -37,6 +38,7 @@ namespace Xamarin.Forms.Platform.Tizen
if (e.NewElement != null)
{
+ Control.BatchBegin();
}
base.OnElementChanged(e);
@@ -47,6 +49,11 @@ namespace Xamarin.Forms.Platform.Tizen
return Control.Measure(Control.MinimumWidth, Control.MinimumHeight).ToDP();
}
+ protected override void OnElementReady()
+ {
+ Control?.BatchCommit();
+ }
+
Native.FormattedString ConvertFormattedText(FormattedString formattedString)
{
if (formattedString == null)
@@ -99,9 +106,13 @@ namespace Xamarin.Forms.Platform.Tizen
void UpdateFontProperties()
{
+ Control.BatchBegin();
+
Control.FontSize = Element.FontSize;
Control.FontAttributes = Element.FontAttributes;
Control.FontFamily = Element.FontFamily;
+
+ Control.BatchCommit();
}
void UpdateLineBreakMode()