mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
Added show() and hide() to StatusBar API
This commit is contained in:
parent
c2f13fe231
commit
7e42f7db49
@ -39,6 +39,9 @@
|
|||||||
- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command;
|
- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command;
|
||||||
- (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command;
|
- (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
|
- (void) hide:(CDVInvokedUrlCommand*)command;
|
||||||
|
- (void) show:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
- (void) _ready:(CDVInvokedUrlCommand*)command;
|
- (void) _ready:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey];
|
NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey];
|
||||||
BOOL boolValue = [newValue boolValue];
|
BOOL boolValue = [newValue boolValue];
|
||||||
|
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", boolValue? @"true" : @"false" ]];
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", boolValue? @"false" : @"true" ]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,17 +91,17 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
|
||||||
if (statusBarOverlaysWebView) {
|
if (statusBarOverlaysWebView) {
|
||||||
|
|
||||||
CGRect bounds = self.viewController.view.bounds;
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
self.webView.frame = bounds;
|
self.webView.frame = bounds;
|
||||||
|
|
||||||
[_statusBarBackgroundView removeFromSuperview];
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
CGRect bounds = self.viewController.view.bounds;
|
bounds.origin.y = statusBarFrame.size.height;
|
||||||
bounds.origin.y += statusBarFrame.size.height;
|
|
||||||
bounds.size.height -= statusBarFrame.size.height;
|
bounds.size.height -= statusBarFrame.size.height;
|
||||||
|
|
||||||
self.webView.frame = bounds;
|
self.webView.frame = bounds;
|
||||||
@ -203,6 +203,61 @@
|
|||||||
[self _backgroundColorByHexString:value];
|
[self _backgroundColorByHexString:value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) hide:(CDVInvokedUrlCommand*)command
|
||||||
|
{
|
||||||
|
UIApplication* app = [UIApplication sharedApplication];
|
||||||
|
|
||||||
|
if (!app.isStatusBarHidden)
|
||||||
|
{
|
||||||
|
self.viewController.wantsFullScreenLayout = YES;
|
||||||
|
[app setStatusBarHidden:YES];
|
||||||
|
|
||||||
|
if (IsAtLeastiOSVersion(@"7.0")) {
|
||||||
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
|
}
|
||||||
|
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
|
||||||
|
self.viewController.view.frame = bounds;
|
||||||
|
self.webView.frame = bounds;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) show:(CDVInvokedUrlCommand*)command
|
||||||
|
{
|
||||||
|
UIApplication* app = [UIApplication sharedApplication];
|
||||||
|
|
||||||
|
if (app.isStatusBarHidden)
|
||||||
|
{
|
||||||
|
BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));
|
||||||
|
self.viewController.wantsFullScreenLayout = isIOS7;
|
||||||
|
|
||||||
|
[app setStatusBarHidden:NO];
|
||||||
|
|
||||||
|
if (isIOS7) {
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||||
|
self.viewController.view.frame = bounds;
|
||||||
|
|
||||||
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
|
|
||||||
|
if (!self.statusBarOverlaysWebView) {
|
||||||
|
bounds.origin.y = statusBarFrame.size.height;
|
||||||
|
bounds.size.height -= statusBarFrame.size.height;
|
||||||
|
|
||||||
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
|
}
|
||||||
|
|
||||||
|
self.webView.frame = bounds;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
CGRect bounds = [[UIScreen mainScreen] applicationFrame];
|
||||||
|
self.viewController.view.frame = bounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"];
|
[[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"];
|
||||||
|
@ -57,6 +57,14 @@ StatusBar.backgroundColorByHexString = function(hexString) {
|
|||||||
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
|
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatusBar.hide = function() {
|
||||||
|
exec(null, null, "StatusBar", "hide", []);
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusBar.show = function() {
|
||||||
|
exec(null, null, "StatusBar", "show", []);
|
||||||
|
}
|
||||||
|
|
||||||
StatusBar.isVisible = true;
|
StatusBar.isVisible = true;
|
||||||
|
|
||||||
module.exports = StatusBar;
|
module.exports = StatusBar;
|
||||||
|
Loading…
Reference in New Issue
Block a user