Skip to content

Commit 1e93a50

Browse files
committed
Added IOSSafeAreaInsets method.
1 parent ea54bf4 commit 1e93a50

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

Plugins/iOS/IOSBridge.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,33 @@ public static class Settings
7272

7373
}
7474

75+
public static class View
76+
{
77+
78+
public struct UIEdgeInsets
79+
{
80+
public float top;
81+
public float left;
82+
public float right;
83+
public float bottom;
84+
}
85+
86+
[DllImport("__Internal")]
87+
private static extern float IOSSafeAreaInsets(string side);
88+
89+
public static UIEdgeInsets IOSSafeAreaInsets()
90+
{
91+
92+
return new UIEdgeInsets
93+
{
94+
top = IOSSafeAreaInsets("top"),
95+
left = IOSSafeAreaInsets("left"),
96+
right = IOSSafeAreaInsets("right"),
97+
bottom = IOSSafeAreaInsets("bottom")
98+
};
99+
100+
}
101+
102+
}
103+
75104
}

Plugins/iOS/IOSBridge.mm

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
extern "C"
66
{
77

8+
bool IOSIsLowPowerModeEnabled() {
9+
return [[NSProcessInfo processInfo] isLowPowerModeEnabled];
10+
}
11+
812
bool IOSPermissionCameraOK() {
913

1014
NSString *mediaType = AVMediaTypeVideo;
@@ -14,8 +18,51 @@ bool IOSPermissionCameraOK() {
1418

1519
}
1620

17-
bool IOSIsLowPowerModeEnabled() {
18-
return [[NSProcessInfo processInfo] isLowPowerModeEnabled];
21+
float IOSSafeAreaInsets(const char* side) {
22+
23+
if (@available(iOS 11.0, *)) {
24+
25+
const NSString* sideString = [NSString stringWithUTF8String: side];
26+
27+
UIWindow *window = UIApplication.sharedApplication.keyWindow;
28+
29+
if ([sideString isEqualToString:@"top"]) {
30+
31+
return window.safeAreaInsets.top;
32+
33+
} else if ([sideString isEqualToString:@"left"]) {
34+
35+
return window.safeAreaInsets.left;
36+
37+
} else if ([sideString isEqualToString:@"right"]) {
38+
39+
return window.safeAreaInsets.right;
40+
41+
} else if ([sideString isEqualToString:@"bottom"]) {
42+
43+
return window.safeAreaInsets.bottom;
44+
45+
} else {
46+
47+
NSException* exception = [NSException
48+
exceptionWithName:NSInvalidArgumentException
49+
reason:@"Invalid side value."
50+
userInfo:nil];
51+
52+
[exception raise];
53+
54+
}
55+
}
56+
57+
NSException* exception = [NSException
58+
exceptionWithName:NSInvalidArgumentException
59+
reason:@"SafeArea only avalible on iOS 11+"
60+
userInfo:nil];
61+
62+
[exception raise];
63+
64+
return false;
65+
1966
}
2067

2168
bool IOSUIAccessibilityIsAssistiveTouchRunning() {

0 commit comments

Comments
 (0)