Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from Rjvs/main
Browse files Browse the repository at this point in the history
Updated for MAUI RC1
  • Loading branch information
drasticactions authored Apr 15, 2022
2 parents d364075 + acde132 commit a2b73d0
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion DrasticMaui.DragAndDropOverlay/DragAndDropOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions DrasticMaui.PageOverlay/PageOverlay.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions DrasticMaui.PageOverlay/PageOverlay.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DrasticMaui.Sample/DrasticMauiSampleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion DrasticMaui.TrayIcon/Window/DrasticTrayWindow.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion DrasticMaui.Window/DrasticMauiWindow.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

#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
{
Expand All @@ -26,7 +29,7 @@ public partial class DrasticMauiWindow
/// <param name="fullScreen">Enable Full Screen.</param>
public void ToggleFullScreen(bool fullScreen)
{
var window = this.Handler?.NativeView as UIWindow;
UIWindow? window = this.Handler?.PlatformView as UIWindow;

if (window is null)
{
Expand Down
5 changes: 4 additions & 1 deletion DrasticMaui/Overlays/BaseOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public BaseOverlay(IWindow window)
/// <inheritdoc/>
public bool IsVisible { get; set; }

/// <inheritdoc/>
public bool IsPlatformViewInitialized { get; set; }

/// <inheritdoc/>
public IWindow Window { get; }

Expand All @@ -66,7 +69,7 @@ public virtual bool Deinitialize()
}

/// <inheritdoc/>
public virtual void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectangleF dirtyRect)
public virtual void Draw(ICanvas canvas, Microsoft.Maui.Graphics.RectF dirtyRect)
{
}

Expand Down
8 changes: 4 additions & 4 deletions DrasticMaui/Tools/PlatformExtensions.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ public static List<T> GetChildView<T>(this Android.Views.ViewGroup view)
/// </summary>
/// <param name="view">MAUI IView.</param>
/// <returns>Rectangle.</returns>
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();

/// <summary>
/// Get the bounding box for an Android View.
/// </summary>
/// <param name="nativeView">Android View.</param>
/// <returns>Rectangle.</returns>
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());
}
}
}
38 changes: 20 additions & 18 deletions DrasticMaui/Tools/PlatformExtensions.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

#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
{
Expand Down Expand Up @@ -46,28 +48,28 @@ public static System.Numerics.Matrix4x4 GetViewTransform(this UIView view)
/// Get Bounding Box.
/// </summary>
/// <param name="view">IView.</param>
/// <returns>Rectangle.</returns>
public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this IView view, IMauiContext context)
/// <returns>Rect.</returns>
public static Microsoft.Maui.Graphics.Rect GetBoundingBox(this IView view, IMauiContext context)
=> view.ToPlatform(context).GetBoundingBox();

/// <summary>
/// Get Bounding Box.
/// </summary>
/// <param name="nativeView">Native View.</param>
/// <returns>Rectangle.</returns>
public static Microsoft.Maui.Graphics.Rectangle GetBoundingBox(this UIView? nativeView)
/// <returns>Rect.</returns>
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);
}

/// <summary>
Expand All @@ -82,13 +84,13 @@ public static double ExtractAngleInRadians(this System.Numerics.Matrix4x4 matrix
/// Get Native View Bounds.
/// </summary>
/// <param name="view">IView.</param>
/// <returns>Rectangle.</returns>
public static Rectangle GetNativeViewBounds(this IView view, IMauiContext context)
/// <returns>Rect.</returns>
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();
Expand All @@ -98,12 +100,12 @@ public static Rectangle GetNativeViewBounds(this IView view, IMauiContext contex
/// Get Native View Bounds.
/// </summary>
/// <param name="nativeView">Native View.</param>
/// <returns>Rectangle.</returns>
public static Rectangle GetNativeViewBounds(this UIView nativeView)
/// <returns>Rect.</returns>
public static Rect GetNativeViewBounds(this UIView nativeView)
{
if (nativeView == null)
{
return default(Rectangle);
return default(Rect);
}

var superview = nativeView;
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a2b73d0

Please sign in to comment.