Implement StatusBar.isVisible

This commit is contained in:
Shazron Abdullah 2013-10-07 17:53:04 -07:00
parent 4be7bcc826
commit c2f13fe231
4 changed files with 45 additions and 2 deletions

View File

@ -21,7 +21,7 @@ Methods
Properties
--------
- StatusBar.isVisible (TODO: not implemented yet)
- StatusBar.isVisible
Permissions
-----------
@ -144,6 +144,21 @@ Supported Platforms
- iOS
StatusBar.isVisible
=================
Read this property to see if the statusbar is visible or not.
if (StatusBar.isVisible) {
// do something
}
Supported Platforms
-------------------
- iOS

View File

@ -39,4 +39,6 @@
- (void) backgroundColorByName:(CDVInvokedUrlCommand*)command;
- (void) backgroundColorByHexString:(CDVInvokedUrlCommand*)command;
- (void) _ready:(CDVInvokedUrlCommand*)command;
@end

View File

@ -40,8 +40,21 @@
}
}
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
{
if ([keyPath isEqual:@"statusBarHidden"]) {
NSNumber* newValue = [change objectForKey:NSKeyValueChangeNewKey];
BOOL boolValue = [newValue boolValue];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", boolValue? @"true" : @"false" ]];
}
}
- (void)pluginInitialize
{
// observe the statusBarHidden property
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
_statusBarOverlaysWebView = YES; // default
CGRect frame = [[UIApplication sharedApplication] statusBarFrame];
@ -65,6 +78,12 @@
}
}
- (void) _ready:(CDVInvokedUrlCommand*)command
{
// set the initial value
[self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", [UIApplication sharedApplication].statusBarHidden? @"false" : @"true" ]];
}
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
{
// we only care about the latest iOS version or a change in setting
@ -184,5 +203,10 @@
[self _backgroundColorByHexString:value];
}
- (void) dealloc
{
[[UIApplication sharedApplication] removeObserver:self forKeyPath:@"statusBarHidden"];
}
@end

View File

@ -23,6 +23,9 @@ var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
exec = require('cordova/exec');
// prime it
exec(null, null, "StatusBar", "_ready", []);
var StatusBar = function() {
};
@ -54,7 +57,6 @@ StatusBar.backgroundColorByHexString = function(hexString) {
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
}
// TODO:
StatusBar.isVisible = true;
module.exports = StatusBar;