Skip to content

Commit

Permalink
perf(DisplayInformation): Add SetOrientationAsync binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 21, 2023
1 parent 582ff39 commit 9cdf0b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
using System.Threading.Tasks;

namespace __Windows.Graphics.Display
{
Expand All @@ -24,6 +25,9 @@ internal static partial class NativeMethods
[JSImport($"{JsType}.getScreenWidth")]
internal static partial float GetScreenWidth();

[JSImport($"{JsType}.setOrientationAsync")]
internal static partial Task SetOrientationAsync(int orientations);

[JSImport($"{JsType}.startDpiChanged")]
internal static partial void StartDpiChanged();

Expand Down
6 changes: 6 additions & 0 deletions src/Uno.UWP/Graphics/Display/DisplayInformation.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public sealed partial class DisplayInformation

private static DisplayInformation InternalGetForCurrentView() => _lazyInstance.Value;

#if !NET7_0_OR_GREATER
private const string JsType = "Windows.Graphics.Display.DisplayInformation";
#endif

public static int DispatchDpiChanged()
{
Expand Down Expand Up @@ -272,7 +274,11 @@ private static DisplayOrientations ParseJsOrientation(string jsOrientation)

private static Task SetOrientationAsync(DisplayOrientations orientations, CancellationToken ct)
{
#if NET7_0_OR_GREATER
return NativeMethods.SetOrientationAsync((int)orientations);
#else
return WebAssemblyRuntime.InvokeAsync($"{JsType}.setOrientationAsync({(int)orientations})", ct);
#endif
}
}
}
Expand Down

0 comments on commit 9cdf0b7

Please sign in to comment.