-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
WindowExtensions.cs
41 lines (35 loc) · 1.06 KB
/
WindowExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Devices;
using UIKit;
namespace Microsoft.Maui.Platform
{
public static partial class WindowExtensions
{
internal static IWindow? GetHostedWindow(this UIWindow? uiWindow)
{
if (uiWindow is null)
return null;
var windows = WindowExtensions.GetWindows();
foreach (var window in windows)
{
if (window.Handler?.PlatformView is UIWindow win)
{
if (win == uiWindow)
return window;
}
}
return null;
}
public static float GetDisplayDensity(this UIWindow uiWindow) =>
(float)(uiWindow.Screen?.Scale ?? new nfloat(1.0f));
#pragma warning disable CA1416 // UIApplication.StatusBarOrientation has [UnsupportedOSPlatform("ios9.0")]. (Deprecated but still works)
internal static DisplayOrientation GetOrientation(this IWindow window) =>
UIApplication.SharedApplication.StatusBarOrientation.IsLandscape()
? DisplayOrientation.Landscape
: DisplayOrientation.Portrait;
#pragma warning restore CA1416
}
}