Skip to content

Commit

Permalink
perf: Add ApplicationView bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 21, 2023
1 parent 6146848 commit a579aa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Uno.UWP/UI/ViewManagement/ApplicationView.Interop.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if NET7_0_OR_GREATER
using System;
using System.Runtime.InteropServices.JavaScript;

namespace __Windows.UI.ViewManagement
Expand All @@ -7,7 +8,15 @@ internal partial class ApplicationView
{
internal static partial class NativeMethods
{
[JSImport("globalThis.Uno.UI.WindowManager.current.getWindowTitle")]
internal static partial string GetWindowTitle();

[JSImport("globalThis.Windows.UI.ViewManagement.ApplicationView.setFullScreenMode")]
internal static partial bool SetFullScreenMode(bool turnOn);

[JSImport("globalThis.Uno.UI.WindowManager.current.setWindowTitle")]
internal static partial void SetWindowTitle(string title);
}
}
}
#endif
#endif
14 changes: 14 additions & 0 deletions src/Uno.UWP/UI/ViewManagement/ApplicationView.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ namespace Windows.UI.ViewManagement
{
partial class ApplicationView
{
#if !NET7_0_OR_GREATER
private const string ApplicationViewTsType = "Windows.UI.ViewManagement.ApplicationView";
#endif

public string Title
{
get
{
#if NET7_0_OR_GREATER
return NativeMethods.GetWindowTitle();
#else
const string command = "Uno.UI.WindowManager.current.getWindowTitle()";
return WebAssemblyRuntime.InvokeJS(command);
#endif
}
set
{
#if NET7_0_OR_GREATER
NativeMethods.SetWindowTitle(value);
#else
var escapedValue = WebAssemblyRuntime.EscapeJs(value);
var command = "Uno.UI.WindowManager.current.setWindowTitle(\"" + escapedValue + "\");";
WebAssemblyRuntime.InvokeJS(command);
#endif
}
}

Expand All @@ -36,9 +46,13 @@ public string Title

private bool SetFullScreenMode(bool turnOn)
{
#if NET7_0_OR_GREATER
return NativeMethods.SetFullScreenMode(turnOn);
#else
var jsEval = $"{ApplicationViewTsType}.setFullScreenMode({turnOn.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()})";
var result = WebAssemblyRuntime.InvokeJS(jsEval);
return bool.TryParse(result, out var modeSwitchSuccessful) && modeSwitchSuccessful;
#endif
}
}
}

0 comments on commit a579aa9

Please sign in to comment.