You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ni...@apache.org on 2020/06/04 14:32:17 UTC
[cordova-plugin-inappbrowser] branch master updated: (ios) Remove
fake status bar with hardcoded height to fix issues in iOS devices with a
notch (#656)
This is an automated email from the ASF dual-hosted git repository.
niklasmerz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-inappbrowser.git
The following commit(s) were added to refs/heads/master by this push:
new 2706f34 (ios) Remove fake status bar with hardcoded height to fix issues in iOS devices with a notch (#656)
2706f34 is described below
commit 2706f3460d8f5e5a05d629711d24d7556b923ce0
Author: PDLMobileApps <46...@users.noreply.github.com>
AuthorDate: Thu Jun 4 10:32:07 2020 -0400
(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 <Al...@PeapodDigitalLabs.com>
---
src/ios/CDVInAppBrowserNavigationController.m | 12 ------
src/ios/CDVWKInAppBrowser.m | 61 +++++++++++++++++++--------
2 files changed, 43 insertions(+), 30 deletions(-)
diff --git a/src/ios/CDVInAppBrowserNavigationController.m b/src/ios/CDVInAppBrowserNavigationController.m
index ff66487..3cc9043 100644
--- a/src/ios/CDVInAppBrowserNavigationController.m
+++ b/src/ios/CDVInAppBrowserNavigationController.m
@@ -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];
}
diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m
index e74734c..3a2ecf8 100644
--- a/src/ios/CDVWKInAppBrowser.m
+++ b/src/ios/CDVWKInAppBrowser.m
@@ -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
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org