Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS) Handle frame origin when status bar isn't overlaying the web view #278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ios/CDVStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ -(void)statusBarDidChangeFrame:(NSNotification*)notification
//add a small delay ( 0.1 seconds ) or statusbar size will be wrong
__weak CDVStatusBar* weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[weakSelf resizeStatusBarBackgroundView];
[weakSelf resizeWebView];
[weakSelf resizeStatusBarBackgroundView];
});
}

Expand Down Expand Up @@ -210,6 +210,8 @@ - (void) initializeStatusBarBackgroundView
statusBarFrame.origin.y = 0;
}

statusBarFrame.size.height = self.webView.frame.origin.y; //frameYStart

_statusBarBackgroundView = [[UIView alloc] initWithFrame:statusBarFrame];
_statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor;
_statusBarBackgroundView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin);
Expand Down Expand Up @@ -421,6 +423,7 @@ - (void) show:(CDVInvokedUrlCommand*)command

-(void)resizeStatusBarBackgroundView {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
statusBarFrame.size.height = self.webView.frame.origin.y; // Set the height to the current webView origin in case it has been changed after resizing
CGRect sbBgFrame = _statusBarBackgroundView.frame;
sbBgFrame.size = statusBarFrame.size;
_statusBarBackgroundView.frame = sbBgFrame;
Expand All @@ -440,11 +443,11 @@ -(void)resizeWebView
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect frame = self.webView.frame;
CGFloat height = statusBarFrame.size.height;
float safeAreaTop = self.webView.safeAreaInsets.top;

if (!self.statusBarOverlaysWebView) {
frame.origin.y = height;
frame.origin.y = height >= safeAreaTop || height == 0 ? height : safeAreaTop;
} else {
float safeAreaTop = self.webView.safeAreaInsets.top;
if (height >= safeAreaTop && safeAreaTop >0) {
// Sometimes when in-call/recording/hotspot larger status bar is present, the safeAreaTop is 40 but we want frame.origin.y to be 20
frame.origin.y = safeAreaTop == 40 ? 20 : height - safeAreaTop;
Expand Down