|
1 |
| -#if __IOS__ |
2 |
| -using System; |
| 1 | +using System; |
3 | 2 | using System.Collections.Generic;
|
4 | 3 | using System.Linq;
|
5 | 4 | using System.Text;
|
@@ -36,37 +35,37 @@ public sealed partial class DisplayInformation
|
36 | 35 |
|
37 | 36 | public uint ScreenHeightInRawPixels
|
38 | 37 | {
|
39 |
| - get |
40 |
| - { |
41 |
| - var screenSize = UIScreen.MainScreen.Bounds.Size; |
42 |
| - var scale = UIScreen.MainScreen.NativeScale; |
43 |
| - return (uint)(screenSize.Height * scale); |
44 |
| - } |
| 38 | + get; |
| 39 | + private set; |
45 | 40 | }
|
46 | 41 |
|
47 | 42 | public uint ScreenWidthInRawPixels
|
48 | 43 | {
|
49 |
| - get |
50 |
| - { |
51 |
| - var screenSize = UIScreen.MainScreen.Bounds.Size; |
52 |
| - var scale = UIScreen.MainScreen.NativeScale; |
53 |
| - return (uint)(screenSize.Width * scale); |
54 |
| - } |
| 44 | + get; |
| 45 | + private set; |
55 | 46 | }
|
56 | 47 |
|
57 |
| - public double RawPixelsPerViewPixel => UIScreen.MainScreen.NativeScale; |
| 48 | + public double RawPixelsPerViewPixel |
| 49 | + { |
| 50 | + get; |
| 51 | + private set; |
| 52 | + } |
58 | 53 |
|
| 54 | + /// <summary> |
| 55 | + /// Scale of 1 is considered @1x, which is the equivalent of 96.0 or 100% for UWP. |
| 56 | + /// https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale |
| 57 | + /// </summary> |
59 | 58 | public float LogicalDpi
|
60 | 59 | {
|
61 |
| - get |
62 |
| - { |
63 |
| - // Scale of 1 is considered @1x, which is the equivalent of 96.0 or 100% for UWP. |
64 |
| - // https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale |
65 |
| - return (float)(UIScreen.MainScreen.Scale * BaseDpi); |
66 |
| - } |
| 60 | + get; |
| 61 | + private set; |
67 | 62 | }
|
68 | 63 |
|
69 |
| - public ResolutionScale ResolutionScale => (ResolutionScale)(int)(UIScreen.MainScreen.Scale * 100.0); |
| 64 | + public ResolutionScale ResolutionScale |
| 65 | + { |
| 66 | + get; |
| 67 | + private set; |
| 68 | + } |
70 | 69 |
|
71 | 70 | /// <summary>
|
72 | 71 | /// Sets the NativeOrientation property
|
@@ -106,6 +105,35 @@ private DisplayOrientations GetCurrentOrientation()
|
106 | 105 | }
|
107 | 106 | }
|
108 | 107 |
|
| 108 | + private void Update() |
| 109 | + { |
| 110 | + var screen = UIScreen.MainScreen; |
| 111 | + var bounds = screen.Bounds; |
| 112 | + |
| 113 | + RawPixelsPerViewPixel = screen.NativeScale; |
| 114 | + ScreenHeightInRawPixels = (uint)(bounds.Height * RawPixelsPerViewPixel); |
| 115 | + ScreenWidthInRawPixels = (uint)(bounds.Width * RawPixelsPerViewPixel); |
| 116 | + |
| 117 | + LogicalDpi = (float)(RawPixelsPerViewPixel * BaseDpi); |
| 118 | + |
| 119 | + ResolutionScale = (ResolutionScale)(int)(RawPixelsPerViewPixel * 100.0); |
| 120 | + } |
| 121 | + |
| 122 | + partial void Initialize() |
| 123 | + { |
| 124 | + NSNotificationCenter |
| 125 | + .DefaultCenter |
| 126 | + .AddObserver( |
| 127 | + UIScreen.ModeDidChangeNotification, |
| 128 | + n => |
| 129 | + { |
| 130 | + Update(); |
| 131 | + } |
| 132 | + ); |
| 133 | + // we are notified on changes but we're already on a screen so let's initialize |
| 134 | + Update(); |
| 135 | + } |
| 136 | + |
109 | 137 | partial void StartOrientationChanged() => ObserveDisplayMetricsChanges();
|
110 | 138 |
|
111 | 139 | partial void StopOrientationChanged() => UnobserveDisplayMetricsChanges();
|
@@ -170,4 +198,3 @@ static partial void SetOrientationPartial(DisplayOrientations orientations)
|
170 | 198 | }
|
171 | 199 | }
|
172 | 200 | }
|
173 |
| -#endif |
|
0 commit comments