From 33e1a65f5985da892d5934cca2f5982c46d0752c Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sat, 9 Dec 2017 22:19:16 -0800 Subject: [PATCH] Implement the platform ticker --- Ooui.Forms/Forms.cs | 36 +++++++++++++++++++++------ Ooui.Forms/Renderers/LabelRenderer.cs | 3 +++ Ooui/UI.cs | 4 ++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Ooui.Forms/Forms.cs b/Ooui.Forms/Forms.cs index c5a39f7..991c264 100644 --- a/Ooui.Forms/Forms.cs +++ b/Ooui.Forms/Forms.cs @@ -30,9 +30,9 @@ namespace Xamarin.Forms Registrar.RegisterAll (new[] { typeof(ExportRendererAttribute), - //typeof(ExportCellAttribute), - //typeof(ExportImageSourceHandlerAttribute), - }); + //typeof(ExportCellAttribute), + //typeof(ExportImageSourceHandlerAttribute), + }); } public static event EventHandler ViewInitialized; @@ -62,11 +62,6 @@ namespace Xamarin.Forms Task.Run (action); } - public Ticker CreateTicker () - { - throw new NotImplementedException (); - } - public Assembly[] GetAssemblies () { return AppDomain.CurrentDomain.GetAssemblies (); @@ -119,6 +114,31 @@ namespace Xamarin.Forms } }), null, (int)interval.TotalMilliseconds, (int)interval.TotalMilliseconds); } + + public Ticker CreateTicker () + { + return new OouiTicker (); + } + + class OouiTicker : Ticker + { + Timer timer; + protected override void DisableTimer () + { + var t = timer; + timer = null; + t?.Dispose (); + } + protected override void EnableTimer () + { + if (timer != null) + return; + var interval = TimeSpan.FromSeconds (1.0 / Ooui.UI.Session.MaxFps); + timer = new Timer ((_ => { + this.SendSignals (); + }), null, (int)interval.TotalMilliseconds, (int)interval.TotalMilliseconds); + } + } } public class ViewInitializedEventArgs diff --git a/Ooui.Forms/Renderers/LabelRenderer.cs b/Ooui.Forms/Renderers/LabelRenderer.cs index df396a3..9be0486 100644 --- a/Ooui.Forms/Renderers/LabelRenderer.cs +++ b/Ooui.Forms/Renderers/LabelRenderer.cs @@ -74,6 +74,9 @@ namespace Ooui.Forms.Renderers { base.OnElementPropertyChanged (sender, e); + if (Control == null) + return; + if (e.PropertyName == Xamarin.Forms.Label.HorizontalTextAlignmentProperty.PropertyName) UpdateAlignment (); else if (e.PropertyName == Xamarin.Forms.Label.VerticalTextAlignmentProperty.PropertyName) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index 768d992..a422abf 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -522,9 +522,11 @@ namespace Ooui readonly HashSet createdIds; readonly List queuedMessages = new List (); + public const int MaxFps = 30; + readonly System.Timers.Timer sendThrottle; DateTime lastTransmitTime = DateTime.MinValue; - readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / 30); // 30 FPS max + readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / MaxFps); readonly double initialWidth; readonly double initialHeight;