diff --git a/src/Uno.UI.Dispatching/Core/CoreDispatcher.wasm.cs b/src/Uno.UI.Dispatching/Core/CoreDispatcher.wasm.cs index c0f452870d11..5eb2ba80ece3 100644 --- a/src/Uno.UI.Dispatching/Core/CoreDispatcher.wasm.cs +++ b/src/Uno.UI.Dispatching/Core/CoreDispatcher.wasm.cs @@ -10,6 +10,10 @@ using Uno.Foundation.Interop; using Uno.Foundation.Logging; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.JavaScript; +#endif + namespace Uno.UI.Dispatching { internal sealed partial class CoreDispatcher @@ -22,6 +26,9 @@ internal sealed partial class CoreDispatcher /// Method invoked from /// #pragma warning disable IDE0051 // Remove unused private members - called by MonoSupport.ts +#if NET7_0_OR_GREATER + [JSExport] +#endif private static int DispatcherCallback() #pragma warning restore IDE0051 // Remove unused private members { diff --git a/src/Uno.UI.Dispatching/Uno.UI.Dispatching.Wasm.csproj b/src/Uno.UI.Dispatching/Uno.UI.Dispatching.Wasm.csproj index eb42ae80ff66..0d3075b639a5 100644 --- a/src/Uno.UI.Dispatching/Uno.UI.Dispatching.Wasm.csproj +++ b/src/Uno.UI.Dispatching/Uno.UI.Dispatching.Wasm.csproj @@ -11,6 +11,7 @@ + true Uno.UI.Dispatching Uno.UI.Dispatching $(DefineConstants);XAMARIN;IS_UNO;IS_UNO_UI_DISPATCHING_PROJECT diff --git a/src/Uno.UI/ts/CoreDispatcher.ts b/src/Uno.UI/ts/CoreDispatcher.ts index d43e03b7576c..0264bfac2e05 100644 --- a/src/Uno.UI/ts/CoreDispatcher.ts +++ b/src/Uno.UI/ts/CoreDispatcher.ts @@ -54,7 +54,11 @@ private static initMethods() { if (!CoreDispatcher._coreDispatcherCallback) { - CoreDispatcher._coreDispatcherCallback = (Module).mono_bind_static_method("[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback"); + if ((globalThis).DotnetExports !== undefined) { + CoreDispatcher._coreDispatcherCallback = (globalThis).DotnetExports.UnoUIDispatching.Uno.UI.Dispatching.CoreDispatcher.DispatcherCallback; + } else { + CoreDispatcher._coreDispatcherCallback = (Module).mono_bind_static_method("[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback"); + } } } } diff --git a/src/Uno.UI/ts/ExportManager.ts b/src/Uno.UI/ts/ExportManager.ts index 8fa02cf85776..d145fdd7e213 100644 --- a/src/Uno.UI/ts/ExportManager.ts +++ b/src/Uno.UI/ts/ExportManager.ts @@ -8,12 +8,14 @@ namespace Uno.UI { if ((Module).getAssemblyExports !== undefined) { const unoExports = await (Module).getAssemblyExports("Uno"); const unoUIExports = await (Module).getAssemblyExports("Uno.UI"); + const unoUIDispatchingExports = await (Module).getAssemblyExports("Uno.UI.Dispatching"); const runtimeWasmExports = await (Module).getAssemblyExports("Uno.Foundation.Runtime.WebAssembly"); (globalThis).DotnetExports = { Uno: unoExports, UnoUI: unoUIExports, + UnoUIDispatching: unoUIDispatchingExports, UnoFoundationRuntimeWebAssembly: runtimeWasmExports }; } diff --git a/src/Uno.UI/ts/MonoSupport.ts b/src/Uno.UI/ts/MonoSupport.ts index fdf8b7889b74..26cc77ef317d 100644 --- a/src/Uno.UI/ts/MonoSupport.ts +++ b/src/Uno.UI/ts/MonoSupport.ts @@ -92,8 +92,12 @@ namespace MonoSupport { public static invokeOnMainThread() { if (!jsCallDispatcher.dispatcherCallback) { - jsCallDispatcher.dispatcherCallback = (Module).mono_bind_static_method( - "[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback"); + if ((globalThis).DotnetExports !== undefined) { + jsCallDispatcher.dispatcherCallback = (globalThis).DotnetExports.UnoUIDispatching.Uno.UI.Dispatching.CoreDispatcher.DispatcherCallback; + } else { + jsCallDispatcher.dispatcherCallback = (Module).mono_bind_static_method( + "[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback"); + } } // Use setImmediate to return avoid blocking the background thread