From acde13222f039c954b15622955289439483806c8 Mon Sep 17 00:00:00 2001 From: Robert J Spencer Date: Thu, 14 Apr 2022 02:52:19 +0800 Subject: [PATCH] Updated for MAUI RC1 Mostly Rectangle->Rect and NativeView -> PlatformView --- .../DragAndDropOverlay.Android.cs | 2 +- .../DragAndDropOverlay.cs | 2 +- .../RealtimeBlurView.Android.cs | 4 +- .../PageOverlay.Android.cs | 6 +-- DrasticMaui.PageOverlay/PageOverlay.iOS.cs | 14 +++---- DrasticMaui.Sample/DrasticMauiSampleWindow.cs | 2 +- .../DrasticSideBarNavigationWindow.Windows.cs | 4 +- .../DrasticSideBarNavigationWindow.iOS.cs | 2 +- .../Window/DrasticTrayWindow.MacCatalyst.cs | 2 +- .../Window/DrasticTrayWindow.Windows.cs | 2 +- .../DrasticMauiWindow.MacCatalyst.cs | 5 ++- DrasticMaui/Overlays/BaseOverlay.cs | 5 ++- .../Tools/PlatformExtensions.Android.cs | 8 ++-- DrasticMaui/Tools/PlatformExtensions.iOS.cs | 38 ++++++++++--------- 14 files changed, 52 insertions(+), 44 deletions(-) diff --git a/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.Android.cs b/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.Android.cs index 1a4c72b..8c88167 100644 --- a/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.Android.cs +++ b/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.Android.cs @@ -49,7 +49,7 @@ public override bool Initialize() return false; } - if (handler.NativeView is not Activity activity) + if (handler.PlatformView is not Activity activity) { return false; } diff --git a/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.cs b/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.cs index 42f6cc4..47726e6 100644 --- a/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.cs +++ b/DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.cs @@ -69,7 +69,7 @@ private class DropElementOverlay : IWindowOverlayElement // We're gonna set if it's invoked externally. public bool Contains(Microsoft.Maui.Graphics.Point point) => false; - public void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectangleF dirtyRect) + public void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectF dirtyRect) { if (!this.IsDragging) { diff --git a/DrasticMaui.Effects/TransparentView/RealtimeBlurView.Android.cs b/DrasticMaui.Effects/TransparentView/RealtimeBlurView.Android.cs index 1de47db..c0d24e5 100644 --- a/DrasticMaui.Effects/TransparentView/RealtimeBlurView.Android.cs +++ b/DrasticMaui.Effects/TransparentView/RealtimeBlurView.Android.cs @@ -116,7 +116,7 @@ public static int BlurProcessingDelayMilliseconds } } - private readonly Rect mRectSrc = new Rect(), mRectDst = new Rect(); + private readonly Android.Graphics.Rect mRectSrc = new Android.Graphics.Rect(), mRectDst = new Android.Graphics.Rect(); // mDecorView should be the root view of the activity (even if you are on a different window like a dialog) // private View mDecorView; @@ -712,7 +712,7 @@ private void DrawRoundedBlurredBitmap(Canvas canvas, Bitmap blurredBitmap, int o //InternalLogger.Debug( // $"BlurView@{GetHashCode()}", $"DrawRoundedBlurredBitmap( mCornerRadius: {mCornerRadius}, mOverlayColor: {mOverlayColor} )"); - var mRectF = new RectF { Right = Width, Bottom = Height }; + var mRectF = new Android.Graphics.RectF { Right = Width, Bottom = Height }; mPaint.Reset(); mPaint.AntiAlias = true; diff --git a/DrasticMaui.PageOverlay/PageOverlay.Android.cs b/DrasticMaui.PageOverlay/PageOverlay.Android.cs index 9663376..0b6acbf 100644 --- a/DrasticMaui.PageOverlay/PageOverlay.Android.cs +++ b/DrasticMaui.PageOverlay/PageOverlay.Android.cs @@ -57,7 +57,7 @@ public override bool Initialize() return false; } - if (handler.NativeView is not Activity activity) + if (handler.PlatformView is not Activity activity) { return false; } @@ -97,7 +97,7 @@ internal void AddNativeElements(Page view) } var pageHandler = view.ToHandler(this.context); - var element = pageHandler?.NativeView; + var element = pageHandler?.PlatformView; if (element is Android.Views.View aView) { aView.Touch += this.Element_Touch; @@ -120,7 +120,7 @@ internal void RemoveNativeElements(Page view) } var pageHandler = view.ToHandler(this.context); - var element = pageHandler?.NativeView; + var element = pageHandler?.PlatformView; if (element is Android.Views.View aView) { aView.Touch -= this.Element_Touch; diff --git a/DrasticMaui.PageOverlay/PageOverlay.iOS.cs b/DrasticMaui.PageOverlay/PageOverlay.iOS.cs index 249a759..f15f8dd 100644 --- a/DrasticMaui.PageOverlay/PageOverlay.iOS.cs +++ b/DrasticMaui.PageOverlay/PageOverlay.iOS.cs @@ -70,15 +70,15 @@ internal void AddNativeElements(Page page) } var element = page.ToHandler(this.context); - if (element.NativeView is null || this.passthroughView is null || this.window?.RootViewController?.View is null) + if (element.PlatformView is null || this.passthroughView is null || this.window?.RootViewController?.View is null) { return; } - element.NativeView.Frame = this.passthroughView.Frame; - element.NativeView.AutoresizingMask = UIViewAutoresizing.All; - this.passthroughView.AddSubview(element.NativeView); - this.passthroughView.BringSubviewToFront(element.NativeView); + element.PlatformView.Frame = this.passthroughView.Frame; + element.PlatformView.AutoresizingMask = UIViewAutoresizing.All; + this.passthroughView.AddSubview(element.PlatformView); + this.passthroughView.BringSubviewToFront(element.PlatformView); this.passthroughView.AutoresizingMask = UIViewAutoresizing.All; this.window?.RootViewController.View.BringSubviewToFront(this.passthroughView); } @@ -95,12 +95,12 @@ internal void RemoveNativeElements(Page page) } var element = page.ToHandler(this.context); - if (element.NativeView is null || this.passthroughView is null || this.window?.RootViewController?.View is null) + if (element.PlatformView is null || this.passthroughView is null || this.window?.RootViewController?.View is null) { return; } - element.NativeView.RemoveFromSuperview(); + element.PlatformView.RemoveFromSuperview(); } private class PassthroughView : UIView diff --git a/DrasticMaui.Sample/DrasticMauiSampleWindow.cs b/DrasticMaui.Sample/DrasticMauiSampleWindow.cs index a3a0a4b..68d4b2d 100644 --- a/DrasticMaui.Sample/DrasticMauiSampleWindow.cs +++ b/DrasticMaui.Sample/DrasticMauiSampleWindow.cs @@ -53,7 +53,7 @@ public async Task TestTrayIcon() #if __MACCATALYST__ if (this.Handler is WindowHandler handler) { - await handler.NativeView.SetFrameForUIWindow(new CoreGraphics.CGRect(0, 0, 100, 100)); + await handler.PlatformView.SetFrameForUIWindow(new CoreGraphics.CGRect(0, 0, 100, 100)); } #endif } diff --git a/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.Windows.cs b/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.Windows.cs index f4dab4f..ab2d3de 100644 --- a/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.Windows.cs +++ b/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.Windows.cs @@ -43,7 +43,7 @@ public async void SetupNavigationView() this.context = handler.MauiContext; - if (handler?.NativeView is not Microsoft.UI.Xaml.Window window) + if (handler?.PlatformView is not Microsoft.UI.Xaml.Window window) { return; } @@ -139,7 +139,7 @@ private void NavigationView_SelectionChanged(Microsoft.UI.Xaml.Controls.Navigati } var testing = selectedItem.Page.ToHandler(this.Handler.MauiContext); - var page = testing.NativeView; + var page = testing.PlatformView; bool addNavigationHandlers = false; if (page != this.page) diff --git a/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.iOS.cs b/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.iOS.cs index 72892c2..d3dfae7 100644 --- a/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.iOS.cs +++ b/DrasticMaui.SidebarNavigationWindow/DrasticSideBarNavigationWindow.iOS.cs @@ -36,7 +36,7 @@ public void SetupNavigationView() return; } - var window = this.Handler?.NativeView as UIWindow; + var window = this.Handler?.PlatformView as UIWindow; if (window is null) { return; diff --git a/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.MacCatalyst.cs b/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.MacCatalyst.cs index 25b45cb..669dd71 100644 --- a/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.MacCatalyst.cs +++ b/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.MacCatalyst.cs @@ -38,7 +38,7 @@ protected override void OnHandlerChanged() private async void SetupWindow() { var handler = this.Handler as Microsoft.Maui.Handlers.WindowHandler; - if (handler?.NativeView is not UIKit.UIWindow uiWindow) + if (handler?.PlatformView is not UIKit.UIWindow uiWindow) { return; } diff --git a/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.Windows.cs b/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.Windows.cs index ca8829b..380242f 100644 --- a/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.Windows.cs +++ b/DrasticMaui.TrayIcon/Window/DrasticTrayWindow.Windows.cs @@ -32,7 +32,7 @@ protected override void OnHandlerChanged() private void SetupWindow() { var handler = this.Handler as Microsoft.Maui.Handlers.WindowHandler; - if (handler?.NativeView is not Microsoft.UI.Xaml.Window window) + if (handler?.PlatformView is not Microsoft.UI.Xaml.Window window) { return; } diff --git a/DrasticMaui.Window/DrasticMauiWindow.MacCatalyst.cs b/DrasticMaui.Window/DrasticMauiWindow.MacCatalyst.cs index fc5580b..896ca9a 100644 --- a/DrasticMaui.Window/DrasticMauiWindow.MacCatalyst.cs +++ b/DrasticMaui.Window/DrasticMauiWindow.MacCatalyst.cs @@ -2,16 +2,19 @@ // Copyright (c) Drastic Actions. All rights reserved. // +#pragma warning disable SA1210 // Using directives need to be in a specific order for MAUI using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; +using Microsoft.Maui.Platform; using DrasticMaui.Tools; using Foundation; using ObjCRuntime; using UIKit; +#pragma warning restore SA1210 // Using directives can't be ordered alphabetically by namespace namespace DrasticMaui { @@ -26,7 +29,7 @@ public partial class DrasticMauiWindow /// Enable Full Screen. public void ToggleFullScreen(bool fullScreen) { - var window = this.Handler?.NativeView as UIWindow; + UIWindow? window = this.Handler?.PlatformView as UIWindow; if (window is null) { diff --git a/DrasticMaui/Overlays/BaseOverlay.cs b/DrasticMaui/Overlays/BaseOverlay.cs index 4d9181e..57e18a7 100644 --- a/DrasticMaui/Overlays/BaseOverlay.cs +++ b/DrasticMaui/Overlays/BaseOverlay.cs @@ -40,6 +40,9 @@ public BaseOverlay(IWindow window) /// public bool IsVisible { get; set; } + /// + public bool IsPlatformViewInitialized { get; set; } + /// public IWindow Window { get; } @@ -66,7 +69,7 @@ public virtual bool Deinitialize() } /// - public virtual void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectangleF dirtyRect) + public virtual void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectF dirtyRect) { } diff --git a/DrasticMaui/Tools/PlatformExtensions.Android.cs b/DrasticMaui/Tools/PlatformExtensions.Android.cs index 1a14601..783916f 100644 --- a/DrasticMaui/Tools/PlatformExtensions.Android.cs +++ b/DrasticMaui/Tools/PlatformExtensions.Android.cs @@ -46,7 +46,7 @@ public static List GetChildView(this Android.Views.ViewGroup view) /// /// MAUI IView. /// Rectangle. - public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this IView view, IMauiContext context) + public static Microsoft.Maui.Graphics.Rect GetBoundingBox(this IView view, IMauiContext context) => view.ToPlatform(context).GetBoundingBox(); /// @@ -54,16 +54,16 @@ public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this IView view, /// /// Android View. /// Rectangle. - public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this Android.Views.View? nativeView) + public static Microsoft.Maui.Graphics.Rect GetBoundingBox(this Android.Views.View? nativeView) { if (nativeView == null) { - return default(Rectangle); + return default(Rect); } var rect = new Android.Graphics.Rect(); nativeView.GetGlobalVisibleRect(rect); - return new Rectangle(rect.ExactCenterX() - (rect.Width() / 2), rect.ExactCenterY() - (rect.Height() / 2), (float)rect.Width(), (float)rect.Height()); + return new Rect(rect.ExactCenterX() - (rect.Width() / 2), rect.ExactCenterY() - (rect.Height() / 2), (float)rect.Width(), (float)rect.Height()); } } } diff --git a/DrasticMaui/Tools/PlatformExtensions.iOS.cs b/DrasticMaui/Tools/PlatformExtensions.iOS.cs index 3a4edbc..8e4f489 100644 --- a/DrasticMaui/Tools/PlatformExtensions.iOS.cs +++ b/DrasticMaui/Tools/PlatformExtensions.iOS.cs @@ -2,14 +2,16 @@ // Copyright (c) Drastic Actions. All rights reserved. // +#pragma warning disable SA1210 // Using directives need to be in a specific order for MAUI +using System.Numerics; +using System.Runtime.InteropServices; +using Microsoft.Maui.Platform; using CoreAnimation; using CoreGraphics; using Foundation; -using Microsoft.Maui.Platform; using ObjCRuntime; -using System.Numerics; -using System.Runtime.InteropServices; using UIKit; +#pragma warning restore SA1210 // Using directives can't be ordered alphabetically by namespace namespace DrasticMaui.Tools { @@ -46,28 +48,28 @@ public static System.Numerics.Matrix4x4 GetViewTransform(this UIView view) /// Get Bounding Box. /// /// IView. - /// Rectangle. - public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this IView view, IMauiContext context) + /// Rect. + public static Microsoft.Maui.Graphics.Rect GetBoundingBox(this IView view, IMauiContext context) => view.ToPlatform(context).GetBoundingBox(); /// /// Get Bounding Box. /// /// Native View. - /// Rectangle. - public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this UIView? nativeView) + /// Rect. + public static Microsoft.Maui.Graphics.Rect GetBoundingBox(this UIView? nativeView) { if (nativeView == null) { - return default(Rectangle); + return default(Rect); } var nvb = nativeView.GetNativeViewBounds(); var transform = nativeView.GetViewTransform(); var radians = transform.ExtractAngleInRadians(); - var rotation = CoreGraphics.CGAffineTransform.MakeRotation((nfloat)radians); + var rotation = CoreGraphics.CGAffineTransform.MakeRotation((NFloat)radians); CGAffineTransform.CGRectApplyAffineTransform(nvb, rotation); - return new Rectangle(nvb.X, nvb.Y, nvb.Width, nvb.Height); + return new Rect(nvb.X, nvb.Y, nvb.Width, nvb.Height); } /// @@ -82,13 +84,13 @@ public static double ExtractAngleInRadians(this System.Numerics.Matrix4x4 matrix /// Get Native View Bounds. /// /// IView. - /// Rectangle. - public static Rectangle GetNativeViewBounds(this IView view, IMauiContext context) + /// Rect. + public static Rect GetNativeViewBounds(this IView view, IMauiContext context) { var nativeView = view?.ToPlatform(context); if (nativeView == null) { - return default(Rectangle); + return default(Rect); } return nativeView.GetNativeViewBounds(); @@ -98,12 +100,12 @@ public static Rectangle GetNativeViewBounds(this IView view, IMauiContext contex /// Get Native View Bounds. /// /// Native View. - /// Rectangle. - public static Rectangle GetNativeViewBounds(this UIView nativeView) + /// Rect. + public static Rect GetNativeViewBounds(this UIView nativeView) { if (nativeView == null) { - return default(Rectangle); + return default(Rect); } var superview = nativeView; @@ -119,7 +121,7 @@ public static Rectangle GetNativeViewBounds(this UIView nativeView) var width = convertPoint.Width; var height = convertPoint.Height; - return new Rectangle(x, y, width, height); + return new Rect(x, y, width, height); } /// @@ -412,7 +414,7 @@ public static void NSApplicationActivateIgnoringOtherApps(bool ignoreSetting = t } [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] - internal static extern IntPtr IntPtr_objc_msgSend_nfloat(IntPtr receiver, IntPtr selector, nfloat arg1); + internal static extern IntPtr IntPtr_objc_msgSend_nfloat(IntPtr receiver, IntPtr selector, NFloat arg1); [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] internal static extern IntPtr IntPtr_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);