Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Patch in iPhoneX notch fix from apache/cordova-plugin-inappbrowser#656
Browse files Browse the repository at this point in the history
  • Loading branch information
dpa99c committed Jun 4, 2020
1 parent cc82578 commit 9b8f923
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
12 changes: 0 additions & 12 deletions src/ios/CDVInAppBrowserNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Licensed to the Apache Software Foundation (ASF) under one

#import "CDVInAppBrowserNavigationController.h"

#define STATUSBAR_HEIGHT 20.0

@implementation CDVInAppBrowserNavigationController : UINavigationController

- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
Expand All @@ -30,16 +28,6 @@ - (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

UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:statusBarFrame];
bgToolbar.barStyle = UIBarStyleDefault;
[bgToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:bgToolbar];

[super viewDidLoad];
}

Expand Down
60 changes: 42 additions & 18 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Licensed to the Apache Software Foundation (ASF) under one
#define IAB_BRIDGE_NAME @"cordova_iab"

#define TOOLBAR_HEIGHT 44.0
#define STATUSBAR_HEIGHT 20.0
#define LOCATIONBAR_HEIGHT 21.0
#define FOOTER_HEIGHT ((TOOLBAR_HEIGHT) + (LOCATIONBAR_HEIGHT))

Expand Down Expand Up @@ -700,7 +699,7 @@ @implementation CDVWKInAppBrowserViewController

@synthesize currentURL;

BOOL viewRenderedAtLeastOnce = FALSE;
CGFloat lastReducedStatusBarHeight = 0.0;
BOOL isExiting = FALSE;

- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings
Expand Down Expand Up @@ -900,7 +899,7 @@ - (void)createViews
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
}

self.view.backgroundColor = [UIColor grayColor];
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.toolbar];
[self.view addSubview:self.addressLabel];
[self.view addSubview:self.spinner];
Expand Down Expand Up @@ -1046,7 +1045,6 @@ - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition

- (void)viewDidLoad
{
viewRenderedAtLeastOnce = FALSE;
[super viewDidLoad];
}

Expand Down Expand Up @@ -1107,14 +1105,6 @@ - (void)goForward:(id)sender

- (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;
self.webView.frame = viewBounds;
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
}
[self rePositionViews];

[super viewWillAppear:animated];
Expand All @@ -1126,16 +1116,28 @@ - (void)viewWillAppear:(BOOL)animated
// change that value.
//
- (float) getStatusBarOffset {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
float statusBarOffset = IsAtLeastiOSVersion(@"7.0") ? MIN(statusBarFrame.size.width, statusBarFrame.size.height) : 0.0;
return statusBarOffset;
return (float) IsAtLeastiOSVersion(@"7.0") ? [[UIApplication sharedApplication] statusBarFrame].size.height : 0.0;
}

- (void) rePositionViews {
if ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]) {
[self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT, self.webView.frame.size.width, self.webView.frame.size.height)];
[self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
CGRect viewBounds = [self.webView bounds];
CGFloat statusBarHeight = [self getStatusBarOffset];

// orientation portrait or portraitUpsideDown: status bar is on the top and web view is to be aligned to the bottom of the status bar
// orientation landscapeLeft or landscapeRight: status bar height is 0 in but lets account for it in case things ever change in the future
viewBounds.origin.y = statusBarHeight;

// account for web view height portion that may have been reduced by a previous call to this method
viewBounds.size.height = viewBounds.size.height - statusBarHeight + lastReducedStatusBarHeight;
lastReducedStatusBarHeight = statusBarHeight;

if ((_browserOptions.toolbar) && ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop])) {
// if we have to display the toolbar on top of the web view, we need to account for its height
viewBounds.origin.y += TOOLBAR_HEIGHT;
self.toolbar.frame = CGRectMake(self.toolbar.frame.origin.x, statusBarHeight, self.toolbar.frame.size.width, self.toolbar.frame.size.height);
}

self.webView.frame = viewBounds;
}

// Helper function to convert hex color string to UIColor
Expand Down Expand Up @@ -1246,6 +1248,28 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations
return 1 << UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
[self rePositionViews];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{

}];

[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

#pragma mark - POPPopupBridgeDelegate

- (void)popupBridge:(POPPopupBridge *)bridge requestsPresentationOfViewController:(UIViewController *)viewController {
Expand Down

0 comments on commit 9b8f923

Please sign in to comment.