Added statusbar plugin.

This controls whether the statusbar overlays the webview in iOS 7, as well as allows changing of the statusbar styles.
This commit is contained in:
Shazron Abdullah 2013-10-04 18:03:18 -07:00
commit 512a1388c6
4 changed files with 241 additions and 0 deletions

38
plugin.xml Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:rim="http://www.blackberry.com/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.statusbar"
version="0.1.0">
<name>StatusBar</name>
<description>Cordova StatusBar Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,statusbar</keywords>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module src="www/statusbar.js" name="statusbar">
<clobbers target="window.StatusBar" />
</js-module>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true" />
</feature>
</config-file>
<config-file target="*-Info.plist" parent="UIViewControllerBasedStatusBarAppearance" >
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</config-file>
<header-file src="src/ios/CDVStatusBar.h" />
<source-file src="src/ios/CDVStatusBar.m" />
</platform>
</plugin>

38
src/ios/CDVStatusBar.h Normal file
View File

@ -0,0 +1,38 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVInvokedUrlCommand.h>
@interface CDVStatusBar : CDVPlugin {
@protected
BOOL _statusBarOverlaysWebView;
}
@property (atomic, assign) BOOL statusBarOverlaysWebView;
- (void) statusBarOverlaysWebView:(CDVInvokedUrlCommand*)command;
- (void) styleDefault:(CDVInvokedUrlCommand*)command;
- (void) styleLightContent:(CDVInvokedUrlCommand*)command;
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
@end

108
src/ios/CDVStatusBar.m Normal file
View File

@ -0,0 +1,108 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/*
NOTE: plugman/cordova cli should have already installed this,
but you need the value UIViewControllerBasedStatusBarAppearance
in your Info.plist as well to set the styles in iOS 7
*/
#import "CDVStatusBar.h"
@implementation CDVStatusBar
- (id)settingForKey:(NSString*)key
{
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
}
- (void)pluginInitialize
{
_statusBarOverlaysWebView = YES; // default
NSString* setting = @"StatusBarOverlaysWebView";
if ([self settingForKey:setting]) {
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
}
}
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
{
// we only care about the latest iOS version or a change in setting
if (!IsAtLeastiOSVersion(@"7.0") || statusBarOverlaysWebView == _statusBarOverlaysWebView) {
return;
}
if (statusBarOverlaysWebView) {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect bounds = self.viewController.view.bounds;
bounds.origin.y = 0;
bounds.size.height += statusBarFrame.size.height;
self.webView.frame = bounds;
} else {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect bounds = self.viewController.view.bounds;
bounds.origin.y += statusBarFrame.size.height;
bounds.size.height -= statusBarFrame.size.height;
self.webView.frame = bounds;
}
_statusBarOverlaysWebView = statusBarOverlaysWebView;
}
- (BOOL) statusBarOverlaysWebView
{
return _statusBarOverlaysWebView;
}
- (void) statusBarOverlaysWebView:(CDVInvokedUrlCommand*)command
{
id value = [command.arguments objectAtIndex:0];
if (!([value isKindOfClass:[NSNumber class]])) {
value = [NSNumber numberWithBool:YES];
}
self.statusBarOverlaysWebView = [value boolValue];
}
- (void) styleDefault:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void) styleLightContent:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
}
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}
@end

57
www/statusbar.js Normal file
View File

@ -0,0 +1,57 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
// var argscheck = require('cordova/argscheck'),
// utils = require('cordova/utils'),
// exec = require('cordova/exec');
(function() {
var exec = cordova.require('cordova/exec')
var StatusBar = function() {
};
StatusBar.statusBarOverlaysWebView = function(doOverlay) {
exec(null, null, "StatusBar", "statusBarOverlaysWebView", [doOverlay]);
};
StatusBar.styleDefault = function() {
exec(null, null, "StatusBar", "styleDefault", []);
};
StatusBar.styleLightContent = function() {
exec(null, null, "StatusBar", "styleLightContent", []);
};
StatusBar.styleBlackTranslucent = function() {
exec(null, null, "StatusBar", "styleBlackTranslucent", []);
};
StatusBar.styleBlackOpaque = function() {
exec(null, null, "StatusBar", "styleBlackOpaque", []);
};
StatusBar.isVisible = true;
window.StatusBar = StatusBar;
})();