Skip to content

Commit

Permalink
[iOS] Notch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Florin9doi committed Mar 31, 2020
1 parent 7dfe895 commit 54b6edb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ - (void)subtleVolume:(SubtleVolume *)volumeView willChange:(CGFloat)value {
- (void)subtleVolume:(SubtleVolume *)volumeView didChange:(CGFloat)value {
}

- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
if (@available(iOS 11.0, *)) {
char safeArea[100];
// we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now)
snprintf(safeArea, sizeof(safeArea), "%f:%f:%f:%f", self.view.safeAreaInsets.left, self.view.safeAreaInsets.right, self.view.safeAreaInsets.top, 0.0f);
System_SendMessage("safe_insets", safeArea);
}
}

- (void)viewDidLoad {
[super viewDidLoad];
[[DisplayManager shared] setupDisplayListener];
Expand Down
21 changes: 21 additions & 0 deletions ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ kern_return_t catch_exception_raise(mach_port_t exception_port,
return NULL;
}

static float g_safeInsetLeft = 0.0;
static float g_safeInsetRight = 0.0;
static float g_safeInsetTop = 0.0;
static float g_safeInsetBottom = 0.0;


std::string System_GetProperty(SystemProperty prop) {
switch (prop) {
Expand Down Expand Up @@ -73,6 +78,14 @@ float System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_REFRESH_RATE:
return 60.f;
case SYSPROP_DISPLAY_SAFE_INSET_LEFT:
return g_safeInsetLeft;
case SYSPROP_DISPLAY_SAFE_INSET_RIGHT:
return g_safeInsetRight;
case SYSPROP_DISPLAY_SAFE_INSET_TOP:
return g_safeInsetTop;
case SYSPROP_DISPLAY_SAFE_INSET_BOTTOM:
return g_safeInsetBottom;
default:
return -1;
}
Expand Down Expand Up @@ -116,6 +129,14 @@ void System_SendMessage(const char *command, const char *parameter) {
} else if (!strcmp(parameter, "close")) {
stopLocation();
}
} else if (!strcmp(command, "safe_insets")) {
float left, right, top, bottom;
if (4 == sscanf(parameter, "%f:%f:%f:%f", &left, &right, &top, &bottom)) {
g_safeInsetLeft = left;
g_safeInsetRight = right;
g_safeInsetTop = top;
g_safeInsetBottom = bottom;
}
}
}

Expand Down

0 comments on commit 54b6edb

Please sign in to comment.