Implement the platform ticker

This commit is contained in:
Frank A. Krueger 2017-12-09 22:19:16 -08:00
parent 88a4798acb
commit 33e1a65f59
3 changed files with 34 additions and 9 deletions

View File

@ -62,11 +62,6 @@ namespace Xamarin.Forms
Task.Run (action); Task.Run (action);
} }
public Ticker CreateTicker ()
{
throw new NotImplementedException ();
}
public Assembly[] GetAssemblies () public Assembly[] GetAssemblies ()
{ {
return AppDomain.CurrentDomain.GetAssemblies (); return AppDomain.CurrentDomain.GetAssemblies ();
@ -119,6 +114,31 @@ namespace Xamarin.Forms
} }
}), null, (int)interval.TotalMilliseconds, (int)interval.TotalMilliseconds); }), 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 public class ViewInitializedEventArgs

View File

@ -74,6 +74,9 @@ namespace Ooui.Forms.Renderers
{ {
base.OnElementPropertyChanged (sender, e); base.OnElementPropertyChanged (sender, e);
if (Control == null)
return;
if (e.PropertyName == Xamarin.Forms.Label.HorizontalTextAlignmentProperty.PropertyName) if (e.PropertyName == Xamarin.Forms.Label.HorizontalTextAlignmentProperty.PropertyName)
UpdateAlignment (); UpdateAlignment ();
else if (e.PropertyName == Xamarin.Forms.Label.VerticalTextAlignmentProperty.PropertyName) else if (e.PropertyName == Xamarin.Forms.Label.VerticalTextAlignmentProperty.PropertyName)

View File

@ -522,9 +522,11 @@ namespace Ooui
readonly HashSet<string> createdIds; readonly HashSet<string> createdIds;
readonly List<Message> queuedMessages = new List<Message> (); readonly List<Message> queuedMessages = new List<Message> ();
public const int MaxFps = 30;
readonly System.Timers.Timer sendThrottle; readonly System.Timers.Timer sendThrottle;
DateTime lastTransmitTime = DateTime.MinValue; 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 initialWidth;
readonly double initialHeight; readonly double initialHeight;