From f78b328759bb673b695c6b0d1a1dac6d871d257a Mon Sep 17 00:00:00 2001 From: adrianknight89 Date: Tue, 10 Jan 2017 18:07:01 -0600 Subject: =?UTF-8?q?iOS=20and=20Android=20timers=20should=20be=20runnable?= =?UTF-8?q?=20from=20any=20thread=20and=20execute=E2=80=A6=20(#374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * iOS and Android timers should be runnable from any thread and executed on the main thread * removing unused Timer class declarations with minor refactoring efforts * iOS and Android timers should be runnable from any thread and executed on the main thread * removing bak file * switch to v7 * add test code --- Xamarin.Forms.Platform.iOS/Forms.cs | 56 +++++-------------------------------- 1 file changed, 7 insertions(+), 49 deletions(-) (limited to 'Xamarin.Forms.Platform.iOS') diff --git a/Xamarin.Forms.Platform.iOS/Forms.cs b/Xamarin.Forms.Platform.iOS/Forms.cs index 06cb1312..5361e13f 100644 --- a/Xamarin.Forms.Platform.iOS/Forms.cs +++ b/Xamarin.Forms.Platform.iOS/Forms.cs @@ -68,9 +68,7 @@ namespace Xamarin.Forms internal static void SendViewInitialized(this VisualElement self, UIView nativeView) { - var viewInitialized = ViewInitialized; - if (viewInitialized != null) - viewInitialized(self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); + ViewInitialized?.Invoke(self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); } class iOSExpressionSearch : ExpressionVisitor, IExpressionSearch @@ -117,15 +115,9 @@ namespace Xamarin.Forms public override Size PixelScreenSize { get; } - public override Size ScaledScreenSize - { - get { return _scaledScreenSize; } - } + public override Size ScaledScreenSize => _scaledScreenSize; - public override double ScalingFactor - { - get { return _scalingFactor; } - } + public override double ScalingFactor => _scalingFactor; protected override void Dispose(bool disposing) { @@ -136,7 +128,7 @@ namespace Xamarin.Forms class IOSPlatformServices : IPlatformServices { - static readonly MD5CryptoServiceProvider Checksum = new MD5CryptoServiceProvider(); + static readonly MD5CryptoServiceProvider s_checksum = new MD5CryptoServiceProvider(); public void BeginInvokeOnMainThread(Action action) { @@ -155,7 +147,7 @@ namespace Xamarin.Forms public string GetMD5Hash(string input) { - var bytes = Checksum.ComputeHash(Encoding.UTF8.GetBytes(input)); + var bytes = s_checksum.ComputeHash(Encoding.UTF8.GetBytes(input)); var ret = new char[32]; for (var i = 0; i < 16; i++) { @@ -198,10 +190,7 @@ namespace Xamarin.Forms return new _IsolatedStorageFile(IsolatedStorageFile.GetUserStoreForApplication()); } - public bool IsInvokeRequired - { - get { return !NSThread.IsMain; } - } + public bool IsInvokeRequired => !NSThread.IsMain; public void OpenUriAction(Uri uri) { @@ -210,8 +199,7 @@ namespace Xamarin.Forms public void StartTimer(TimeSpan interval, Func callback) { - NSTimer timer = null; - timer = NSTimer.CreateRepeatingScheduledTimer(interval, t => + NSTimer timer = NSTimer.CreateRepeatingTimer(interval, t => { if (!callback()) t.Invalidate(); @@ -238,36 +226,6 @@ namespace Xamarin.Forms return 'a' + v - 10; } - public class _Timer : ITimer - { - readonly Timer _timer; - - public _Timer(Timer timer) - { - _timer = timer; - } - - public void Change(int dueTime, int period) - { - _timer.Change(dueTime, period); - } - - public void Change(long dueTime, long period) - { - _timer.Change(dueTime, period); - } - - public void Change(TimeSpan dueTime, TimeSpan period) - { - _timer.Change(dueTime, period); - } - - public void Change(uint dueTime, uint period) - { - _timer.Change(dueTime, period); - } - } - public class _IsolatedStorageFile : IIsolatedStorageFile { readonly IsolatedStorageFile _isolatedStorageFile; -- cgit v1.2.3