Skip to content

Commit

Permalink
Corrected webview and toolbar position and size
Browse files Browse the repository at this point in the history
Set statusbarcolor from grey to clear to fix >= iphone x issues
  • Loading branch information
Kevin-Hamilton authored Sep 11, 2019
1 parent 2b59941 commit dd31f32
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/ios/CDVUIInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Licensed to the Apache Software Foundation (ASF) under one
#define kInAppBrowserToolbarBarPositionTop @"top"

#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 @@ -620,6 +619,8 @@ @implementation CDVUIInAppBrowserViewController

@synthesize currentURL;

BOOL viewUIRenderedAtLeastOnce = FALSE;

- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions
{
self = [super init];
Expand Down Expand Up @@ -775,7 +776,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 @@ -916,6 +917,7 @@ - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition

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

Expand Down Expand Up @@ -988,7 +990,15 @@ - (void)goForward:(id)sender

- (void)viewWillAppear:(BOOL)animated
{
if (IsAtLeastiOSVersion(@"7.0")) {
if (IsAtLeastiOSVersion(@"7.0") && !viewUIRenderedAtLeastOnce) {
viewUIRenderedAtLeastOnce = TRUE;
CGRect viewBounds = [self.webView bounds];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGFloat statusBarHeight = statusBarFrame.size.height;
viewBounds.origin.y = statusBarHeight;
viewBounds.size.height = viewBounds.size.height - statusBarHeight;

self.webView.frame = viewBounds;
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
}
[self rePositionViews];
Expand All @@ -1008,8 +1018,10 @@ - (float) getStatusBarOffset {
}

- (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)];
if ((_browserOptions.toolbar) && ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop])) {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGFloat statusBarHeight = statusBarFrame.size.height;
[self.webView setFrame:CGRectMake(self.webView.frame.origin.x, TOOLBAR_HEIGHT + [self getStatusBarOffset], self.webView.frame.size.width, self.webView.frame.size.height - [self getStatusBarOffset] + statusBarHeight)];
[self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
}
}
Expand Down

0 comments on commit dd31f32

Please sign in to comment.