mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 09:22:50 +08:00
Fixes CB-4712, CB-5439 statusbar issues
Fixes CB-4712, CB-5439 and hopefully all the statusbar issues related to the size or resize of the cordova webview when the status bar changes the size and/or rotation and resizes first time
This commit is contained in:
parent
3795486e33
commit
86b9edba5d
@ -90,6 +90,16 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)statusBarDidChangeFrame:(NSNotification*)notification
|
||||||
|
{
|
||||||
|
//add a small delay for iOS 7
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
|
[self resizeWebView];
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
- (void)pluginInitialize
|
- (void)pluginInitialize
|
||||||
{
|
{
|
||||||
BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
||||||
@ -101,6 +111,8 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
// observe the statusBarHidden property
|
// observe the statusBarHidden property
|
||||||
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
|
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name: UIApplicationDidChangeStatusBarFrameNotification object:nil];
|
||||||
|
|
||||||
_statusBarOverlaysWebView = YES; // default
|
_statusBarOverlaysWebView = YES; // default
|
||||||
|
|
||||||
[self initializeStatusBarBackgroundView];
|
[self initializeStatusBarBackgroundView];
|
||||||
@ -109,11 +121,6 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
|
|
||||||
NSString* setting;
|
NSString* setting;
|
||||||
|
|
||||||
setting = @"StatusBarOverlaysWebView";
|
|
||||||
if ([self settingForKey:setting]) {
|
|
||||||
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
setting = @"StatusBarBackgroundColor";
|
setting = @"StatusBarBackgroundColor";
|
||||||
if ([self settingForKey:setting]) {
|
if ([self settingForKey:setting]) {
|
||||||
[self _backgroundColorByHexString:[self settingForKey:setting]];
|
[self _backgroundColorByHexString:[self settingForKey:setting]];
|
||||||
@ -158,11 +165,17 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
[self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId];
|
[self.commandDelegate sendPluginResult:result callbackId:_eventsCallbackId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) _ready:(CDVInvokedUrlCommand*)command
|
- (void) _ready:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
_eventsCallbackId = command.callbackId;
|
_eventsCallbackId = command.callbackId;
|
||||||
[self updateIsVisible:![UIApplication sharedApplication].statusBarHidden];
|
[self updateIsVisible:![UIApplication sharedApplication].statusBarHidden];
|
||||||
|
NSString* setting = @"StatusBarOverlaysWebView";
|
||||||
|
if ([self settingForKey:setting]) {
|
||||||
|
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
|
||||||
|
if (self.statusBarOverlaysWebView) {
|
||||||
|
[self resizeWebView];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) initializeStatusBarBackgroundView
|
- (void) initializeStatusBarBackgroundView
|
||||||
@ -196,33 +209,21 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
_statusBarOverlaysWebView = statusBarOverlaysWebView;
|
||||||
|
|
||||||
|
[self resizeWebView];
|
||||||
|
|
||||||
if (statusBarOverlaysWebView) {
|
if (statusBarOverlaysWebView) {
|
||||||
|
|
||||||
[_statusBarBackgroundView removeFromSuperview];
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
|
|
||||||
self.webView.frame = CGRectMake(0, 0, bounds.size.height, bounds.size.width);
|
|
||||||
} else {
|
|
||||||
self.webView.frame = bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
|
||||||
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
|
||||||
|
|
||||||
[self initializeStatusBarBackgroundView];
|
[self initializeStatusBarBackgroundView];
|
||||||
|
|
||||||
CGRect frame = self.webView.frame;
|
|
||||||
frame.origin.y = statusBarFrame.size.height;
|
|
||||||
frame.size.height -= statusBarFrame.size.height;
|
|
||||||
|
|
||||||
self.webView.frame = frame;
|
|
||||||
[self.webView.superview addSubview:_statusBarBackgroundView];
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_statusBarOverlaysWebView = statusBarOverlaysWebView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) statusBarOverlaysWebView
|
- (BOOL) statusBarOverlaysWebView
|
||||||
@ -366,7 +367,6 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
|
|
||||||
if (!app.isStatusBarHidden)
|
if (!app.isStatusBarHidden)
|
||||||
{
|
{
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
|
||||||
|
|
||||||
[self hideStatusBar];
|
[self hideStatusBar];
|
||||||
|
|
||||||
@ -374,16 +374,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
[_statusBarBackgroundView removeFromSuperview];
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_statusBarOverlaysWebView) {
|
[self resizeWebView];
|
||||||
|
|
||||||
CGRect frame = self.webView.frame;
|
|
||||||
frame.origin.y = 0;
|
|
||||||
if (!self.statusBarOverlaysWebView) {
|
|
||||||
frame.size.height += MIN(statusBarFrame.size.height, statusBarFrame.size.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.webView.frame = frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
_statusBarBackgroundView.hidden = YES;
|
_statusBarBackgroundView.hidden = YES;
|
||||||
}
|
}
|
||||||
@ -413,27 +404,22 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
[self showStatusBar];
|
[self showStatusBar];
|
||||||
|
|
||||||
if (isIOS7) {
|
if (isIOS7) {
|
||||||
CGRect frame = self.webView.frame;
|
|
||||||
self.viewController.view.frame = [[UIScreen mainScreen] bounds];
|
|
||||||
|
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
[self resizeWebView];
|
||||||
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
|
||||||
|
|
||||||
if (!self.statusBarOverlaysWebView) {
|
if (!self.statusBarOverlaysWebView) {
|
||||||
|
|
||||||
// there is a possibility that when the statusbar was hidden, it was in a different orientation
|
// there is a possibility that when the statusbar was hidden, it was in a different orientation
|
||||||
// from the current one. Therefore we need to expand the statusBarBackgroundView as well to the
|
// from the current one. Therefore we need to expand the statusBarBackgroundView as well to the
|
||||||
// statusBar's current size
|
// statusBar's current size
|
||||||
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
|
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
||||||
CGRect sbBgFrame = _statusBarBackgroundView.frame;
|
CGRect sbBgFrame = _statusBarBackgroundView.frame;
|
||||||
frame.origin.y = statusBarFrame.size.height;
|
|
||||||
frame.size.height -= statusBarFrame.size.height;
|
|
||||||
sbBgFrame.size = statusBarFrame.size;
|
sbBgFrame.size = statusBarFrame.size;
|
||||||
|
|
||||||
_statusBarBackgroundView.frame = sbBgFrame;
|
_statusBarBackgroundView.frame = sbBgFrame;
|
||||||
[self.webView.superview addSubview:_statusBarBackgroundView];
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
}
|
|
||||||
|
|
||||||
self.webView.frame = frame;
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -445,9 +431,35 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)resizeWebView {
|
||||||
|
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
|
||||||
|
bounds = [self invertFrameIfNeeded:bounds orientation:self.viewController.interfaceOrientation];
|
||||||
|
|
||||||
|
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
|
||||||
|
self.viewController.view.frame = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.webView.frame = bounds;
|
||||||
|
|
||||||
|
if (!self.statusBarOverlaysWebView) {
|
||||||
|
|
||||||
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
|
statusBarFrame = [self invertFrameIfNeeded:statusBarFrame orientation:self.viewController.interfaceOrientation];
|
||||||
|
|
||||||
|
CGRect frame = self.webView.frame;
|
||||||
|
frame.origin.y = statusBarFrame.size.height;
|
||||||
|
frame.size.height -= statusBarFrame.size.height;
|
||||||
|
self.webView.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"];
|
[[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:UIApplicationDidChangeStatusBarFrameNotification];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user