From 6c7f6db4197e1f3908eb936ad295420012ffee02 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Wed, 31 May 2023 02:58:06 -0400 Subject: [PATCH] perf: Add Alert binding --- src/Uno.UWP/UI/Popups/MessageDialog.Interop.wasm.cs | 4 +++- src/Uno.UWP/UI/Popups/MessageDialog.wasm.cs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Uno.UWP/UI/Popups/MessageDialog.Interop.wasm.cs b/src/Uno.UWP/UI/Popups/MessageDialog.Interop.wasm.cs index 245fd67dc871..3bfa16a52d79 100644 --- a/src/Uno.UWP/UI/Popups/MessageDialog.Interop.wasm.cs +++ b/src/Uno.UWP/UI/Popups/MessageDialog.Interop.wasm.cs @@ -7,7 +7,9 @@ internal partial class MessageDialog { internal static partial class NativeMethods { + [JSImport("globalThis.alert")] + internal static partial void Alert(string message); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/UI/Popups/MessageDialog.wasm.cs b/src/Uno.UWP/UI/Popups/MessageDialog.wasm.cs index 907726332374..e59520ca5e57 100644 --- a/src/Uno.UWP/UI/Popups/MessageDialog.wasm.cs +++ b/src/Uno.UWP/UI/Popups/MessageDialog.wasm.cs @@ -23,8 +23,12 @@ private IAsyncOperation ShowNativeAsync(CancellationToken ct) { VisualTreeHelperProxy.CloseAllFlyouts(); +#if NET7_0_OR_GREATER + NativeMethods.Alert(Content); +#else var command = $"Uno.UI.WindowManager.current.alert(\"{Uno.Foundation.WebAssemblyRuntime.EscapeJs(Content)}\");"; Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); +#endif return AsyncOperation.FromTask( ct => Task.FromResult(new UICommand("OK")) // TODO: Localize (PBI 28711)