Skip to content

Commit

Permalink
Add top notch detection
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasMerz committed Sep 25, 2019
1 parent 80feff6 commit 0c75a93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/ios/CDVInAppBrowserNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ - (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))com
- (void) viewDidLoad {

CGRect statusBarFrame = [self invertFrameIfNeeded:[UIApplication sharedApplication].statusBarFrame];
statusBarFrame.size.height = STATUSBAR_HEIGHT;
// simplified from: http://stackoverflow.com/a/25669695/219684

//simplified from https://github.com/apache/cordova-plugin-inappbrowser/issues/301#issuecomment-452220131
//and https://stackoverflow.com/questions/46192280/detect-if-the-device-is-iphone-x
bool hasTopNotch = NO;
if (@available(iOS 11.0, *)) {
hasTopNotch = [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0;
}
if(hasTopNotch){
statusBarFrame.size.height = 0;
} else {
statusBarFrame.size.height = STATUSBAR_HEIGHT;
}

// simplified from: http://stackoverflow.com/a/25669695/219684
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:statusBarFrame];
bgToolbar.barStyle = UIBarStyleDefault;
[bgToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
Expand Down
14 changes: 12 additions & 2 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,18 @@ - (void)viewWillAppear:(BOOL)animated
if (IsAtLeastiOSVersion(@"7.0") && !viewRenderedAtLeastOnce) {
viewRenderedAtLeastOnce = TRUE;
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = STATUSBAR_HEIGHT;
viewBounds.size.height = viewBounds.size.height - STATUSBAR_HEIGHT;

//simplified from https://github.com/apache/cordova-plugin-inappbrowser/issues/301#issuecomment-452220131
//and https://stackoverflow.com/questions/46192280/detect-if-the-device-is-iphone-x
bool hasTopNotch = NO;
if (@available(iOS 11.0, *)) {
hasTopNotch = [[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0;
}
if(!hasTopNotch){
viewBounds.origin.y = STATUSBAR_HEIGHT;
viewBounds.size.height = viewBounds.size.height - STATUSBAR_HEIGHT;
}

self.webView.frame = viewBounds;
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
}
Expand Down

0 comments on commit 0c75a93

Please sign in to comment.