diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs index 1bfd7f23a411943747158821922e36786dc3f4aa..9c55fa3df56555bc21cd51aa4eb862d2e9d30f1b 100644 --- a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs +++ b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObject.wasm.cs @@ -5,14 +5,21 @@ using System.Reflection; using System.Runtime.InteropServices; // using Uno.Logging; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.JavaScript; +#endif + namespace Uno.Foundation.Interop { [Obfuscation(Feature = "renaming", Exclude = true)] - public sealed class JSObject + public sealed partial class JSObject { /// /// Used by javascript to dispatch a method call to the managed object at . /// +#if NET7_0_OR_GREATER + [JSExport] +#endif [Obfuscation(Feature = "renaming", Exclude = true)] public static void Dispatch(IntPtr handlePtr, string method, string parameters) { diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectHandle.wasm.cs b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectHandle.wasm.cs index 619e7e57f0f0d2aa4acd75a9173a205ddc84baa3..a099b1119a3c1585e1a2daf5ccd905b759ef80b0 100644 --- a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectHandle.wasm.cs +++ b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectHandle.wasm.cs @@ -49,6 +49,10 @@ namespace Uno.Foundation.Interop /// public bool IsAlive { get; private set; } + internal long JSHandle => _jsHandle; + + internal nint ManagedHandle => _managedHandle; + /// /// Metadata about the marshaled object /// diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj b/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj index 423a325e9037c8875ad546e9e6f80f5d1f67d804..4eb88facadba1fad2a721373258ec3ddb4d8555b 100644 --- a/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj +++ b/src/Uno.Foundation.Runtime.WebAssembly/Uno.Foundation.Runtime.WebAssembly.csproj @@ -11,6 +11,7 @@ $(NoWarn);NU1701 + true $(DefineConstants);IS_UNO_FOUNDATION_RUNTIME_WEBASSEMBLY_PROJECT false diff --git a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs index 5d5b9491cd83559a37c69b276dd87d0f0ee94387..1ac2889cb1cbf60ff6185dc122d7b7aeb1d60abf 100644 --- a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.Interop.wasm.cs @@ -13,6 +13,18 @@ namespace __Windows.UI.Xaml.Media.Animation [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.destroyInstance")] internal static partial void DestroyInstance(double jsHandle); + + [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.disableFrameReporting")] + internal static partial void DisableFrameReporting(double jsHandle); + + [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.enableFrameReporting")] + internal static partial void EnableFrameReporting(double jsHandle); + + [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.setAnimationFramesInterval")] + internal static partial void SetAnimationFramesInterval(double jsHandle); + + [JSImport("globalThis.Windows.UI.Xaml.Media.Animation.RenderingLoopAnimator.setStartFrameDelay")] + internal static partial void SetStartFrameDelay(double jsHandle, double delayMs); } } } diff --git a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs index 0f68d26e45a2b739b3ace2146e6a80f0203ddb2c..a046a4cc6888cfa1acab1bbf35d320945bf271cf 100644 --- a/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Media/Animation/Animators/RenderingLoopAnimator.wasm.cs @@ -25,7 +25,11 @@ namespace Windows.UI.Xaml.Media.Animation { if (Handle.IsAlive) { +#if NET7_0_OR_GREATER + NativeMethods.EnableFrameReporting(Handle.JSHandle); +#else WebAssemblyRuntime.InvokeJSWithInterop($"{this}.EnableFrameReporting();"); +#endif } else if (this.Log().IsEnabled(LogLevel.Debug)) { @@ -37,7 +41,11 @@ namespace Windows.UI.Xaml.Media.Animation { if (Handle.IsAlive) { +#if NET7_0_OR_GREATER + NativeMethods.DisableFrameReporting(Handle.JSHandle); +#else WebAssemblyRuntime.InvokeJSWithInterop($"{this}.DisableFrameReporting();"); +#endif } else if (this.Log().IsEnabled(LogLevel.Debug)) { @@ -49,7 +57,11 @@ namespace Windows.UI.Xaml.Media.Animation { if (Handle.IsAlive) { +#if NET7_0_OR_GREATER + NativeMethods.SetStartFrameDelay(Handle.JSHandle, delayMs); +#else WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetStartFrameDelay({delayMs});"); +#endif } else if (this.Log().IsEnabled(LogLevel.Debug)) { @@ -61,7 +73,11 @@ namespace Windows.UI.Xaml.Media.Animation { if (Handle.IsAlive) { +#if NET7_0_OR_GREATER + NativeMethods.SetAnimationFramesInterval(Handle.JSHandle); +#else WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetAnimationFramesInterval();"); +#endif } else if (this.Log().IsEnabled(LogLevel.Debug)) { diff --git a/src/Uno.UI/ts/ExportManager.ts b/src/Uno.UI/ts/ExportManager.ts index bb4e9436dfb2f854e44009c49a72c15a2a0c7a79..8fa02cf857760ff1cf03b9b627bd1c505bdbc20d 100644 --- a/src/Uno.UI/ts/ExportManager.ts +++ b/src/Uno.UI/ts/ExportManager.ts @@ -9,7 +9,13 @@ namespace Uno.UI { const unoExports = await (Module).getAssemblyExports("Uno"); const unoUIExports = await (Module).getAssemblyExports("Uno.UI"); - (globalThis).DotnetExports = { Uno: unoExports, UnoUI: unoUIExports }; + const runtimeWasmExports = await (Module).getAssemblyExports("Uno.Foundation.Runtime.WebAssembly"); + + (globalThis).DotnetExports = { + Uno: unoExports, + UnoUI: unoUIExports, + UnoFoundationRuntimeWebAssembly: runtimeWasmExports + }; } } } diff --git a/src/Uno.UI/ts/Interop/ManagedObject.ts b/src/Uno.UI/ts/Interop/ManagedObject.ts index 51ac2846295080bb161c66701ddb9b6963b3c205..7493a31637ac79fa9fafe0970d625abfc5c82be6 100644 --- a/src/Uno.UI/ts/Interop/ManagedObject.ts +++ b/src/Uno.UI/ts/Interop/ManagedObject.ts @@ -4,7 +4,13 @@ private static dispatchMethod: (handle: number, method: string, parameters: string) => number; private static init() { - ManagedObject.dispatchMethod = (Module).mono_bind_static_method("[Uno.Foundation.Runtime.WebAssembly] Uno.Foundation.Interop.JSObject:Dispatch"); + const exports = (globalThis).DotnetExports?.UnoFoundationRuntimeWebAssembly?.Uno?.Foundation?.Interop?.JSObject; + + if (exports !== undefined) { + ManagedObject.dispatchMethod = exports.Dispatch; + } else { + ManagedObject.dispatchMethod = (Module).mono_bind_static_method("[Uno.Foundation.Runtime.WebAssembly] Uno.Foundation.Interop.JSObject:Dispatch"); + } } public static dispatch(handle: number, method: string, parameters: string): void { diff --git a/src/Uno.UI/ts/Windows/UI/Xaml/Animation/RenderingLoopAnimator.ts b/src/Uno.UI/ts/Windows/UI/Xaml/Animation/RenderingLoopAnimator.ts index 9ba77938bade1b90748374ee469c07179ffd22ed..435788e7763f2f9bc2a5511aa5eb46f792f0351d 100644 --- a/src/Uno.UI/ts/Windows/UI/Xaml/Animation/RenderingLoopAnimator.ts +++ b/src/Uno.UI/ts/Windows/UI/Xaml/Animation/RenderingLoopAnimator.ts @@ -23,6 +23,10 @@ private constructor(private managedHandle: number) { } + public static setStartFrameDelay(jsHandle: number, delay: number) { + RenderingLoopAnimator.getInstance(jsHandle).SetStartFrameDelay(delay); + } + public SetStartFrameDelay(delay: number) { this.unscheduleFrame(); @@ -31,6 +35,10 @@ } } + public static setAnimationFramesInterval(jsHandle: number) { + RenderingLoopAnimator.getInstance(jsHandle).SetAnimationFramesInterval(); + } + public SetAnimationFramesInterval() { this.unscheduleFrame(); @@ -39,6 +47,10 @@ } } + public static enableFrameReporting(jsHandle: number) { + RenderingLoopAnimator.getInstance(jsHandle).EnableFrameReporting(); + } + public EnableFrameReporting() { if (this._isEnabled) { return; @@ -48,6 +60,10 @@ this.scheduleAnimationFrame(); } + public static disableFrameReporting(jsHandle: number) { + RenderingLoopAnimator.getInstance(jsHandle).DisableFrameReporting(); + } + public DisableFrameReporting() { this._isEnabled = false; this.unscheduleFrame();