(ios) Remove fake status bar with hardcoded height to fix issues in iOS devices with a notch (#656)
* (ios) Removed fake statusbar with hardcoded height to fix issues in iOS devices with a notch * (ios) Removed no longer needed bgToolbar * (ios) Fixed issue with rotation in landscape mode and refactored/simplified the code Co-authored-by: Alessandro Basso <Alessandro.Basso@PeapodDigitalLabs.com>
This commit is contained in:
parent
dcfe692ccd
commit
2706f3460d
@ -19,8 +19,6 @@
|
||||
|
||||
#import "CDVInAppBrowserNavigationController.h"
|
||||
|
||||
#define STATUSBAR_HEIGHT 20.0
|
||||
|
||||
@implementation CDVInAppBrowserNavigationController : UINavigationController
|
||||
|
||||
- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
|
||||
@ -30,16 +28,6 @@
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,6 @@
|
||||
#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))
|
||||
|
||||
@ -698,7 +697,7 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
|
||||
@synthesize currentURL;
|
||||
|
||||
BOOL viewRenderedAtLeastOnce = FALSE;
|
||||
CGFloat lastReducedStatusBarHeight = 0.0;
|
||||
BOOL isExiting = FALSE;
|
||||
|
||||
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings
|
||||
@ -896,7 +895,7 @@ BOOL isExiting = FALSE;
|
||||
[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];
|
||||
@ -1042,7 +1041,6 @@ BOOL isExiting = FALSE;
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
viewRenderedAtLeastOnce = FALSE;
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
@ -1103,14 +1101,6 @@ BOOL isExiting = FALSE;
|
||||
|
||||
- (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];
|
||||
@ -1122,16 +1112,28 @@ BOOL isExiting = FALSE;
|
||||
// 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
|
||||
@ -1242,4 +1244,27 @@ BOOL isExiting = FALSE;
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@end //CDVWKInAppBrowserViewController
|
||||
|
Loading…
Reference in New Issue
Block a user