From 34b4f970e9fca967bbcbc5df7e2aec27e9a6d918 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 28 Feb 2022 20:45:23 -0500 Subject: [PATCH] Avoid "using system" because --- 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, 41 insertions(+), 48 deletions(-) diff --git a/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs b/src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs index 65a6743f9d..e1b5189845 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 5bb2f64879..c789c07d00 100644 --- a/src/iOS/Avalonia.iOS/AvaloniaView.cs +++ b/src/iOS/Avalonia.iOS/AvaloniaView.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Embedding; @@ -94,14 +93,14 @@ namespace Avalonia.iOS public Size? FrameSize => null; public double RenderScaling => _view.ContentScaleFactor; public IEnumerable Surfaces { 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; } + 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; } // 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 b9f74d69c6..9b230016c7 100644 --- a/src/iOS/Avalonia.iOS/ClipboardImpl.cs +++ b/src/iOS/Avalonia.iOS/ClipboardImpl.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Avalonia.Input; using Avalonia.Input.Platform; @@ -25,10 +24,10 @@ namespace Avalonia.iOS return Task.FromResult(0); } - public Task SetDataObjectAsync(IDataObject data) => throw new PlatformNotSupportedException(); + public Task SetDataObjectAsync(IDataObject data) => throw new System.PlatformNotSupportedException(); - public Task GetFormatsAsync() => throw new PlatformNotSupportedException(); + public Task GetFormatsAsync() => throw new System.PlatformNotSupportedException(); - public Task GetDataAsync(string format) => throw new PlatformNotSupportedException(); + public Task GetDataAsync(string format) => throw new System.PlatformNotSupportedException(); } -} \ No newline at end of file +} diff --git a/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs b/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs index df73479a65..f92f0b1aa2 100644 --- a/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs +++ b/src/iOS/Avalonia.iOS/DisplayLinkTimer.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -11,7 +10,7 @@ namespace Avalonia.iOS { class DisplayLinkTimer : IRenderTimer { - public event Action Tick; + public event System.Action Tick; private Stopwatch _st = Stopwatch.StartNew(); public DisplayLinkTimer() @@ -34,4 +33,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 bd1969081d..c24895e733 100644 --- a/src/iOS/Avalonia.iOS/EaglDisplay.cs +++ b/src/iOS/Avalonia.iOS/EaglDisplay.cs @@ -1,4 +1,3 @@ -using System; using System.Reactive.Disposables; using Avalonia.OpenGL; using OpenGLES; @@ -8,7 +7,7 @@ namespace Avalonia.iOS class EaglFeature : IPlatformOpenGlInterface { public IGlContext PrimaryContext => Context; - public IGlContext CreateSharedContext() => throw new NotSupportedException(); + public IGlContext CreateSharedContext() => throw new System.NotSupportedException(); public bool CanShareContexts => false; public bool CanCreateContexts => false; public IGlContext CreateContext() => throw new System.NotSupportedException(); @@ -23,7 +22,7 @@ namespace Avalonia.iOS { const string path = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES"; var libGl = ObjCRuntime.Dlfcn.dlopen(path, 1); - if (libGl == IntPtr.Zero) + if (libGl == System.IntPtr.Zero) throw new OpenGlException("Unable to load " + path); GlInterface = new GlInterface(Version, proc => ObjCRuntime.Dlfcn.dlsym(libGl, proc)); Context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); @@ -35,7 +34,7 @@ namespace Avalonia.iOS Context = null; } - class ResetContext : IDisposable + class ResetContext : System.IDisposable { private EAGLContext _old; private bool _disposed; @@ -55,7 +54,7 @@ namespace Avalonia.iOS } } - public IDisposable MakeCurrent() + public System.IDisposable MakeCurrent() { var old = EAGLContext.CurrentContext; if (!EAGLContext.SetCurrentContext(Context)) @@ -63,7 +62,7 @@ namespace Avalonia.iOS return new ResetContext(old); } - public IDisposable EnsureCurrent() + public System.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 0e8945d921..5d714077bc 100644 --- a/src/iOS/Avalonia.iOS/EaglLayerSurface.cs +++ b/src/iOS/Avalonia.iOS/EaglLayerSurface.cs @@ -1,5 +1,3 @@ - -using System; using System.Threading; using Avalonia.OpenGL; using Avalonia.OpenGL.Surfaces; @@ -19,10 +17,10 @@ namespace Avalonia.iOS class RenderSession : IGlPlatformSurfaceRenderingSession { private readonly GlContext _ctx; - private readonly IDisposable _restoreContext; + private readonly System.IDisposable _restoreContext; private readonly SizeSynchronizedLayerFbo _fbo; - public RenderSession(GlContext ctx, IDisposable restoreContext, SizeSynchronizedLayerFbo fbo) + public RenderSession(GlContext ctx, System.IDisposable restoreContext, SizeSynchronizedLayerFbo fbo) { _ctx = ctx; _restoreContext = restoreContext; @@ -75,7 +73,7 @@ namespace Avalonia.iOS static void CheckThread() { if (Platform.Timer.TimerThread != Thread.CurrentThread) - throw new InvalidOperationException("Invalid thread, go away"); + throw new System.InvalidOperationException("Invalid thread, go away"); } public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() @@ -86,7 +84,7 @@ namespace Avalonia.iOS { var fbo = new SizeSynchronizedLayerFbo(ctx.Context, ctx.GlInterface, _layer); if (!fbo.Sync()) - throw new InvalidOperationException("Unable to create render target"); + throw new System.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 80f6b419c9..d57a22ddf3 100644 --- a/src/iOS/Avalonia.iOS/Extensions.cs +++ b/src/iOS/Avalonia.iOS/Extensions.cs @@ -1,4 +1,3 @@ -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 955aaef59f..e221a9c9b3 100644 --- a/src/iOS/Avalonia.iOS/LayerFbo.cs +++ b/src/iOS/Avalonia.iOS/LayerFbo.cs @@ -1,8 +1,12 @@ -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 @@ -92,11 +96,11 @@ namespace Avalonia.iOS _gl.DeleteRenderbuffers(1, _depthBuffer); _gl.DeleteRenderbuffers(1, _renderbuffer); if (_context != EAGLContext.CurrentContext) - throw new InvalidOperationException("Associated EAGLContext is not current"); + throw new System.InvalidOperationException("Associated EAGLContext is not current"); } } - class SizeSynchronizedLayerFbo : IDisposable + class SizeSynchronizedLayerFbo : System.IDisposable { private readonly EAGLContext _context; private readonly GlInterface _gl; @@ -130,7 +134,7 @@ namespace Avalonia.iOS public void Dispose() { if (_context != EAGLContext.CurrentContext) - throw new InvalidOperationException("Associated EAGLContext is not current"); + throw new System.InvalidOperationException("Associated EAGLContext is not current"); _fbo?.Dispose(); _fbo = null; } @@ -138,7 +142,7 @@ namespace Avalonia.iOS public void Bind() { if(!Sync()) - throw new InvalidOperationException("Unable to create a render target"); + throw new System.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 57a86cbfd8..4c31c192c6 100644 --- a/src/iOS/Avalonia.iOS/Platform.cs +++ b/src/iOS/Avalonia.iOS/Platform.cs @@ -1,5 +1,3 @@ -using System; - using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; @@ -32,11 +30,11 @@ namespace Avalonia.iOS public Size TouchDoubleClickSize => new Size(10, 10); /// - public TimeSpan TouchDoubleClickTime => TimeSpan.FromMilliseconds(500); + public System.TimeSpan TouchDoubleClickTime => System.TimeSpan.FromMilliseconds(500); public Size DoubleClickSize => new Size(4, 4); - public TimeSpan DoubleClickTime => TouchDoubleClickTime; + public System.TimeSpan DoubleClickTime => TouchDoubleClickTime; } public static void Register() diff --git a/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs b/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs index fa36ab6c79..c9e8f36c44 100644 --- a/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs +++ b/src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs @@ -1,4 +1,3 @@ -using System; using System.Threading; using Avalonia.Platform; using Avalonia.Threading; @@ -13,14 +12,14 @@ namespace Avalonia.iOS public static PlatformThreadingInterface Instance { get; } = new PlatformThreadingInterface(); public bool CurrentThreadIsLoopThread => NSThread.Current.IsMainThread; - public event Action Signaled; + public event System.Action Signaled; public void RunLoop(CancellationToken cancellationToken) { //Mobile platforms are using external main loop - throw new NotSupportedException(); + throw new System.NotSupportedException(); } - public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) + public System.IDisposable StartTimer(DispatcherPriority priority, System.TimeSpan interval, System.Action tick) => NSTimer.CreateRepeatingScheduledTimer(interval, _ => tick()); public void Signal(DispatcherPriority prio) @@ -40,4 +39,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 9c46aa78cc..3ec582a254 100644 --- a/src/iOS/Avalonia.iOS/Stubs.cs +++ b/src/iOS/Avalonia.iOS/Stubs.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using Avalonia.Input; using Avalonia.Platform; @@ -18,9 +17,9 @@ namespace Avalonia.iOS class WindowingPlatformStub : IWindowingPlatform { - public IWindowImpl CreateWindow() => throw new NotSupportedException(); + public IWindowImpl CreateWindow() => throw new System.NotSupportedException(); - public IWindowImpl CreateEmbeddableWindow() => throw new NotSupportedException(); + public IWindowImpl CreateEmbeddableWindow() => throw new System.NotSupportedException(); public ITrayIconImpl CreateTrayIcon() => null; }