From 3344e436b384d6284f8fa5ee16deeaee833aa3bb Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sat, 5 Mar 2022 17:40:50 +0000 Subject: [PATCH] Revert "Avoid "using system" because" This reverts commit 34b4f970e9fca967bbcbc5df7e2aec27e9a6d918. --- src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs | 2 +- src/iOS/Avalonia.iOS/AvaloniaView.cs | 17 +++++++++-------- src/iOS/Avalonia.iOS/ClipboardImpl.cs | 9 +++++---- src/iOS/Avalonia.iOS/DisplayLinkTimer.cs | 5 +++-- src/iOS/Avalonia.iOS/EaglDisplay.cs | 11 ++++++----- src/iOS/Avalonia.iOS/EaglLayerSurface.cs | 10 ++++++---- src/iOS/Avalonia.iOS/Extensions.cs | 1 + src/iOS/Avalonia.iOS/LayerFbo.cs | 14 +++++--------- src/iOS/Avalonia.iOS/Platform.cs | 6 ++++-- .../Avalonia.iOS/PlatformThreadingInterface.cs | 9 +++++---- src/iOS/Avalonia.iOS/Stubs.cs | 5 +++-- 11 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs b/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs index e1b5189845..65a6743f9d 100644 --- a/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs +++ b/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs @@ -12,7 +12,7 @@ namespace Avalonia.iOS [Export("window")] public UIWindow Window { get; set; } - + [Export("application:didFinishLaunchingWithOptions:")] public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { diff --git a/src/iOS/Avalonia.iOS/AvaloniaView.cs b/src/iOS/Avalonia.iOS/AvaloniaView.cs index c789c07d00..5bb2f64879 100644 --- a/src/iOS/Avalonia.iOS/AvaloniaView.cs +++ b/src/iOS/Avalonia.iOS/AvaloniaView.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Embedding; @@ -93,14 +94,14 @@ namespace Avalonia.iOS public Size? FrameSize => null; public double RenderScaling => _view.ContentScaleFactor; public IEnumerable Surfaces { get; set; } - public System.Action Input { get; set; } - public System.Action Paint { get; set; } - public System.Action Resized { get; set; } - public System.Action ScalingChanged { get; set; } - public System.Action TransparencyLevelChanged { get; set; } - public System.Action Closed { get; set; } - - public System.Action LostFocus { get; set; } + public Action Input { get; set; } + public Action Paint { get; set; } + public Action Resized { get; set; } + public Action ScalingChanged { get; set; } + public Action TransparencyLevelChanged { get; set; } + public Action Closed { get; set; } + + public Action LostFocus { get; set; } // legacy no-op public IMouseDevice MouseDevice { get; } = new MouseDevice(); diff --git a/src/iOS/Avalonia.iOS/ClipboardImpl.cs b/src/iOS/Avalonia.iOS/ClipboardImpl.cs index 9b230016c7..b9f74d69c6 100644 --- a/src/iOS/Avalonia.iOS/ClipboardImpl.cs +++ b/src/iOS/Avalonia.iOS/ClipboardImpl.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Avalonia.Input; using Avalonia.Input.Platform; @@ -24,10 +25,10 @@ namespace Avalonia.iOS return Task.FromResult(0); } - public Task SetDataObjectAsync(IDataObject data) => throw new System.PlatformNotSupportedException(); + public Task SetDataObjectAsync(IDataObject data) => throw new PlatformNotSupportedException(); - public Task GetFormatsAsync() => throw new System.PlatformNotSupportedException(); + public Task GetFormatsAsync() => throw new PlatformNotSupportedException(); - public Task GetDataAsync(string format) => throw new System.PlatformNotSupportedException(); + public Task GetDataAsync(string format) => throw new PlatformNotSupportedException(); } -} +} \ No newline at end of file diff --git a/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs b/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs index f92f0b1aa2..df73479a65 100644 --- a/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs +++ b/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -10,7 +11,7 @@ namespace Avalonia.iOS { class DisplayLinkTimer : IRenderTimer { - public event System.Action Tick; + public event Action Tick; private Stopwatch _st = Stopwatch.StartNew(); public DisplayLinkTimer() @@ -33,4 +34,4 @@ namespace Avalonia.iOS Tick?.Invoke(_st.Elapsed); } } -} +} \ No newline at end of file diff --git a/src/iOS/Avalonia.iOS/EaglDisplay.cs b/src/iOS/Avalonia.iOS/EaglDisplay.cs index c24895e733..bd1969081d 100644 --- a/src/iOS/Avalonia.iOS/EaglDisplay.cs +++ b/src/iOS/Avalonia.iOS/EaglDisplay.cs @@ -1,3 +1,4 @@ +using System; using System.Reactive.Disposables; using Avalonia.OpenGL; using OpenGLES; @@ -7,7 +8,7 @@ namespace Avalonia.iOS class EaglFeature : IPlatformOpenGlInterface { public IGlContext PrimaryContext => Context; - public IGlContext CreateSharedContext() => throw new System.NotSupportedException(); + public IGlContext CreateSharedContext() => throw new NotSupportedException(); public bool CanShareContexts => false; public bool CanCreateContexts => false; public IGlContext CreateContext() => throw new System.NotSupportedException(); @@ -22,7 +23,7 @@ namespace Avalonia.iOS { const string path = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES"; var libGl = ObjCRuntime.Dlfcn.dlopen(path, 1); - if (libGl == System.IntPtr.Zero) + if (libGl == IntPtr.Zero) throw new OpenGlException("Unable to load " + path); GlInterface = new GlInterface(Version, proc => ObjCRuntime.Dlfcn.dlsym(libGl, proc)); Context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); @@ -34,7 +35,7 @@ namespace Avalonia.iOS Context = null; } - class ResetContext : System.IDisposable + class ResetContext : IDisposable { private EAGLContext _old; private bool _disposed; @@ -54,7 +55,7 @@ namespace Avalonia.iOS } } - public System.IDisposable MakeCurrent() + public IDisposable MakeCurrent() { var old = EAGLContext.CurrentContext; if (!EAGLContext.SetCurrentContext(Context)) @@ -62,7 +63,7 @@ namespace Avalonia.iOS return new ResetContext(old); } - public System.IDisposable EnsureCurrent() + public IDisposable EnsureCurrent() { if(EAGLContext.CurrentContext == Context) return Disposable.Empty; diff --git a/src/iOS/Avalonia.iOS/EaglLayerSurface.cs b/src/iOS/Avalonia.iOS/EaglLayerSurface.cs index 5d714077bc..0e8945d921 100644 --- a/src/iOS/Avalonia.iOS/EaglLayerSurface.cs +++ b/src/iOS/Avalonia.iOS/EaglLayerSurface.cs @@ -1,3 +1,5 @@ + +using System; using System.Threading; using Avalonia.OpenGL; using Avalonia.OpenGL.Surfaces; @@ -17,10 +19,10 @@ namespace Avalonia.iOS class RenderSession : IGlPlatformSurfaceRenderingSession { private readonly GlContext _ctx; - private readonly System.IDisposable _restoreContext; + private readonly IDisposable _restoreContext; private readonly SizeSynchronizedLayerFbo _fbo; - public RenderSession(GlContext ctx, System.IDisposable restoreContext, SizeSynchronizedLayerFbo fbo) + public RenderSession(GlContext ctx, IDisposable restoreContext, SizeSynchronizedLayerFbo fbo) { _ctx = ctx; _restoreContext = restoreContext; @@ -73,7 +75,7 @@ namespace Avalonia.iOS static void CheckThread() { if (Platform.Timer.TimerThread != Thread.CurrentThread) - throw new System.InvalidOperationException("Invalid thread, go away"); + throw new InvalidOperationException("Invalid thread, go away"); } public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() @@ -84,7 +86,7 @@ namespace Avalonia.iOS { var fbo = new SizeSynchronizedLayerFbo(ctx.Context, ctx.GlInterface, _layer); if (!fbo.Sync()) - throw new System.InvalidOperationException("Unable to create render target"); + throw new InvalidOperationException("Unable to create render target"); return new RenderTarget(ctx, fbo); } } diff --git a/src/iOS/Avalonia.iOS/Extensions.cs b/src/iOS/Avalonia.iOS/Extensions.cs index d57a22ddf3..80f6b419c9 100644 --- a/src/iOS/Avalonia.iOS/Extensions.cs +++ b/src/iOS/Avalonia.iOS/Extensions.cs @@ -1,3 +1,4 @@ +using System; using Avalonia.Media; using CoreGraphics; using UIKit; diff --git a/src/iOS/Avalonia.iOS/LayerFbo.cs b/src/iOS/Avalonia.iOS/LayerFbo.cs index e221a9c9b3..955aaef59f 100644 --- a/src/iOS/Avalonia.iOS/LayerFbo.cs +++ b/src/iOS/Avalonia.iOS/LayerFbo.cs @@ -1,12 +1,8 @@ +using System; using Avalonia.OpenGL; using CoreAnimation; using OpenGLES; -// We can't import System because System has a type called nint on iOS and Mac Catalyst. -// As such, throughout this file System is fully qualified. -// See https://github.com/xamarin/xamarin-macios/issues/10508 -// And https://github.com/dotnet/Silk.NET/blob/main/src/Windowing/Silk.NET.Windowing.Sdl/SdlView.cs - namespace Avalonia.iOS { public class LayerFbo @@ -96,11 +92,11 @@ namespace Avalonia.iOS _gl.DeleteRenderbuffers(1, _depthBuffer); _gl.DeleteRenderbuffers(1, _renderbuffer); if (_context != EAGLContext.CurrentContext) - throw new System.InvalidOperationException("Associated EAGLContext is not current"); + throw new InvalidOperationException("Associated EAGLContext is not current"); } } - class SizeSynchronizedLayerFbo : System.IDisposable + class SizeSynchronizedLayerFbo : IDisposable { private readonly EAGLContext _context; private readonly GlInterface _gl; @@ -134,7 +130,7 @@ namespace Avalonia.iOS public void Dispose() { if (_context != EAGLContext.CurrentContext) - throw new System.InvalidOperationException("Associated EAGLContext is not current"); + throw new InvalidOperationException("Associated EAGLContext is not current"); _fbo?.Dispose(); _fbo = null; } @@ -142,7 +138,7 @@ namespace Avalonia.iOS public void Bind() { if(!Sync()) - throw new System.InvalidOperationException("Unable to create a render target"); + throw new InvalidOperationException("Unable to create a render target"); _fbo.Bind(); } diff --git a/src/iOS/Avalonia.iOS/Platform.cs b/src/iOS/Avalonia.iOS/Platform.cs index 4c31c192c6..57a86cbfd8 100644 --- a/src/iOS/Avalonia.iOS/Platform.cs +++ b/src/iOS/Avalonia.iOS/Platform.cs @@ -1,3 +1,5 @@ +using System; + using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; @@ -30,11 +32,11 @@ namespace Avalonia.iOS public Size TouchDoubleClickSize => new Size(10, 10); /// - public System.TimeSpan TouchDoubleClickTime => System.TimeSpan.FromMilliseconds(500); + public TimeSpan TouchDoubleClickTime => TimeSpan.FromMilliseconds(500); public Size DoubleClickSize => new Size(4, 4); - public System.TimeSpan DoubleClickTime => TouchDoubleClickTime; + public TimeSpan DoubleClickTime => TouchDoubleClickTime; } public static void Register() diff --git a/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs b/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs index c9e8f36c44..fa36ab6c79 100644 --- a/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs +++ b/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs @@ -1,3 +1,4 @@ +using System; using System.Threading; using Avalonia.Platform; using Avalonia.Threading; @@ -12,14 +13,14 @@ namespace Avalonia.iOS public static PlatformThreadingInterface Instance { get; } = new PlatformThreadingInterface(); public bool CurrentThreadIsLoopThread => NSThread.Current.IsMainThread; - public event System.Action Signaled; + public event Action Signaled; public void RunLoop(CancellationToken cancellationToken) { //Mobile platforms are using external main loop - throw new System.NotSupportedException(); + throw new NotSupportedException(); } - public System.IDisposable StartTimer(DispatcherPriority priority, System.TimeSpan interval, System.Action tick) + public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) => NSTimer.CreateRepeatingScheduledTimer(interval, _ => tick()); public void Signal(DispatcherPriority prio) @@ -39,4 +40,4 @@ namespace Avalonia.iOS }); } } -} +} \ No newline at end of file diff --git a/src/iOS/Avalonia.iOS/Stubs.cs b/src/iOS/Avalonia.iOS/Stubs.cs index 3ec582a254..9c46aa78cc 100644 --- a/src/iOS/Avalonia.iOS/Stubs.cs +++ b/src/iOS/Avalonia.iOS/Stubs.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using Avalonia.Input; using Avalonia.Platform; @@ -17,9 +18,9 @@ namespace Avalonia.iOS class WindowingPlatformStub : IWindowingPlatform { - public IWindowImpl CreateWindow() => throw new System.NotSupportedException(); + public IWindowImpl CreateWindow() => throw new NotSupportedException(); - public IWindowImpl CreateEmbeddableWindow() => throw new System.NotSupportedException(); + public IWindowImpl CreateEmbeddableWindow() => throw new NotSupportedException(); public ITrayIconImpl CreateTrayIcon() => null; }