commit 512a1388c65fc099b56c0a40e6c63458b2d029eb Author: Shazron Abdullah Date: Fri Oct 4 18:03:18 2013 -0700 Added statusbar plugin. This controls whether the statusbar overlays the webview in iOS 7, as well as allows changing of the statusbar styles. diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ad69b14 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,38 @@ + + + + StatusBar + Cordova StatusBar Plugin + Apache 2.0 + cordova,statusbar + + + + + + + + + + + + + + + + + + + UIViewControllerBasedStatusBarAppearance + + + + + + + + diff --git a/src/ios/CDVStatusBar.h b/src/ios/CDVStatusBar.h new file mode 100644 index 0000000..298b3f5 --- /dev/null +++ b/src/ios/CDVStatusBar.h @@ -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 +#import + +@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 diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m new file mode 100644 index 0000000..9fe4632 --- /dev/null +++ b/src/ios/CDVStatusBar.m @@ -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 diff --git a/www/statusbar.js b/www/statusbar.js new file mode 100644 index 0000000..4f1886a --- /dev/null +++ b/www/statusbar.js @@ -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; + +})(); \ No newline at end of file