From 6abcdd8567436bbff8a3329da0786155b2cb6307 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 1 May 2024 19:59:59 +0200 Subject: [PATCH] feat: Implement AppWindow Move and Resize on WASM --- .../Factory/NativeWindowFactory.singlewindow.cs | 2 +- .../Native/NativeWindowWrapper.Interop.wasm.cs | 6 ++++++ .../Xaml/Window/Native/NativeWindowWrapper.wasm.cs | 9 ++++++--- src/Uno.UI/ts/WindowManager.ts | 12 ++++++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs b/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs index f39066d4aae8..a503f04f5232 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/Factory/NativeWindowFactory.singlewindow.cs @@ -13,7 +13,7 @@ partial class NativeWindowFactory private static INativeWindowWrapper? CreateWindowPlatform(Microsoft.UI.Xaml.Window window, XamlRoot xamlRoot) { - NativeWindowWrapper.Instance.SetXamlRoot(xamlRoot); + NativeWindowWrapper.Instance.SetWindow(window, xamlRoot); return NativeWindowWrapper.Instance; } } diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.Interop.wasm.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.Interop.wasm.cs index 69cf55d58f0b..8417b85eff7a 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.Interop.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.Interop.wasm.cs @@ -19,5 +19,11 @@ internal static partial class NativeMethods [JSImport("globalThis.Uno.UI.WindowManager.current.setWindowTitle")] internal static partial void SetWindowTitle(string title); + + [JSImport("globalThis.Uno.UI.WindowManager.current.resizeWindow")] + internal static partial void ResizeWindow(int width, int height); + + [JSImport("globalThis.Uno.UI.WindowManager.current.moveWindow")] + internal static partial void MoveWindow(int x, int y); } } diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs index efc5b15b92d9..4d3747998c93 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.wasm.cs @@ -1,8 +1,7 @@ using System; -using System.Runtime.InteropServices.JavaScript; using Uno.Disposables; -using Uno.Foundation.Logging; using Windows.Foundation; +using Windows.Graphics; using Windows.Graphics.Display; using Windows.UI.Core; using static __Uno.UI.Xaml.Controls.NativeWindowWrapper; @@ -40,7 +39,7 @@ private void DispatchDpiChanged() => internal void OnNativeActivated(CoreWindowActivationState state) => ActivationState = state; - internal void OnNativeVisibilityChanged(bool visible) => Visible = visible; + internal void OnNativeVisibilityChanged(bool visible) => IsVisible = visible; internal void RaiseNativeSizeChanged(double width, double height) { @@ -69,4 +68,8 @@ protected override IDisposable ApplyFullScreenPresenter() SetFullScreenMode(true); return Disposable.Create(() => SetFullScreenMode(false)); } + + public override void Move(PointInt32 position) => NativeMethods.MoveWindow(position.X, position.Y); + + public override void Resize(SizeInt32 size) => NativeMethods.ResizeWindow(size.Width, size.Height); } diff --git a/src/Uno.UI/ts/WindowManager.ts b/src/Uno.UI/ts/WindowManager.ts index dd4abf12beaf..1cb003d2cbf8 100644 --- a/src/Uno.UI/ts/WindowManager.ts +++ b/src/Uno.UI/ts/WindowManager.ts @@ -1638,7 +1638,7 @@ namespace Uno.UI { if (element) { element.parentElement.removeChild(element); } - + let bootstrapperLoaders = document.getElementsByClassName(WindowManager.unoPersistentLoaderClassName); if (bootstrapperLoaders.length > 0) { let bootstrapperLoader = bootstrapperLoaders[0] as HTMLElement; @@ -1743,7 +1743,7 @@ namespace Uno.UI { public getIsOverflowing(elementId: number): boolean { const element = this.getView(elementId) as HTMLElement; - + return element.clientWidth < element.scrollWidth || element.clientHeight < element.scrollHeight; } @@ -1752,6 +1752,14 @@ namespace Uno.UI { element.setAttribute("tabindex", isFocusable ? "0" : "-1"); } + + public resizeWindow(width: number, height: number) { + window.resizeTo(width, height); + } + + public moveWindow(x: number, y: number) { + window.moveTo(x, y); + } } if (typeof define === "function") {