You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/06/03 00:34:03 UTC

git commit: CB-6783 - added StatusBarStyle config preference, updated docs (closes #9)

Repository: cordova-plugin-statusbar
Updated Branches:
  refs/heads/master 4cfee575a -> 55575f540


CB-6783 - added StatusBarStyle config preference,  updated docs (closes #9)

Signed-off-by: Shazron Abdullah <sh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/55575f54
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/55575f54
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/55575f54

Branch: refs/heads/master
Commit: 55575f5409cbfa0fe521168c06763008c8c6bc09
Parents: 4cfee57
Author: pelish8 <pe...@gmail.com>
Authored: Thu May 15 14:05:14 2014 +0200
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Jun 2 15:32:36 2014 -0700

----------------------------------------------------------------------
 doc/index.md           |  27 ++++++-----
 plugin.xml             |   7 +--
 src/ios/CDVStatusBar.m | 108 +++++++++++++++++++++++---------------------
 3 files changed, 75 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/55575f54/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index a3dab68..aa773f4 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -32,11 +32,15 @@ Preferences
 -  __StatusBarOverlaysWebView__ (boolean, defaults to true). On iOS 7, make the statusbar overlay or not overlay the WebView at startup.
 
         <preference name="StatusBarOverlaysWebView" value="true" />
-            
+
 - __StatusBarBackgroundColor__ (color hex string, defaults to #000000). On iOS 7, set the background color of the statusbar by a hex string (#RRGGBB) at startup.
 
         <preference name="StatusBarBackgroundColor" value="#000000" />
 
+- __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque.
+
+        <preference name="StatusBarStyle" value="lightcontent" />
+
 Hiding at startup
 -----------
 
@@ -50,7 +54,7 @@ Add/edit these two attributes if not present. Set **"Status bar is initially hid
 	<key>UIViewControllerBasedStatusBarAppearance</key>
 	<false/>
 
- 
+
 Methods
 -------
 
@@ -114,7 +118,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.styleLightContent
@@ -129,7 +133,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.styleBlackTranslucent
@@ -144,7 +148,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.styleBlackOpaque
@@ -159,7 +163,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 
@@ -179,7 +183,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.backgroundColorByHexString
@@ -202,7 +206,7 @@ Supported Platforms
 -------------------
 
 - iOS
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.hide
@@ -218,7 +222,7 @@ Supported Platforms
 
 - iOS
 - Android
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 StatusBar.show
@@ -234,7 +238,7 @@ Supported Platforms
 
 - iOS
 - Android
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 
@@ -253,8 +257,7 @@ Supported Platforms
 
 - iOS
 - Android
-- Windows Phone 7 
+- Windows Phone 7
 - Windows Phone 8
 
 
-    
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/55575f54/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 9adb60e..32790e5 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -35,7 +35,7 @@
     <js-module src="www/statusbar.js" name="statusbar">
         <clobbers target="window.StatusBar" />
     </js-module>
-    
+
     <platform name="android">
         <source-file src="src/android/StatusBar.java" target-dir="src/org/apache/cordova/statusbar" />
 
@@ -55,11 +55,12 @@
             </feature>
             <preference name="StatusBarOverlaysWebView" value="true" />
             <preference name="StatusBarBackgroundColor" value="#000000" />
+            <preference name="StatusBarStyle" value="lightcontent" />
         </config-file>
-        
+
         <header-file src="src/ios/CDVStatusBar.h" />
         <source-file src="src/ios/CDVStatusBar.m" />
-        
+
     </platform>
 
     <!-- wp7 -->

http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/55575f54/src/ios/CDVStatusBar.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m
index af93134..e954a54 100644
--- a/src/ios/CDVStatusBar.m
+++ b/src/ios/CDVStatusBar.m
@@ -6,9 +6,9 @@
  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
@@ -17,7 +17,7 @@
  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
@@ -34,18 +34,18 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
 
 @property (nonatomic, retain) id sb_hideStatusBar;
 @property (nonatomic, retain) id sb_statusBarStyle;
-    
+
 @end
 
 @implementation CDVViewController (StatusBar)
 
 @dynamic sb_hideStatusBar;
 @dynamic sb_statusBarStyle;
-    
+
 - (id)sb_hideStatusBar {
     return objc_getAssociatedObject(self, kHideStatusBar);
 }
-    
+
 - (void)setSb_hideStatusBar:(id)newHideStatusBar {
     objc_setAssociatedObject(self, kHideStatusBar, newHideStatusBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
 }
@@ -53,20 +53,20 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
 - (id)sb_statusBarStyle {
     return objc_getAssociatedObject(self, kStatusBarStyle);
 }
-    
+
 - (void)setSb_statusBarStyle:(id)newStatusBarStyle {
     objc_setAssociatedObject(self, kStatusBarStyle, newStatusBarStyle, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
 }
-    
+
 - (BOOL) prefersStatusBarHidden {
     return [self.sb_hideStatusBar boolValue];
 }
-    
+
 - (UIStatusBarStyle)preferredStatusBarStyle
 {
     return (UIStatusBarStyle)[self.sb_statusBarStyle intValue];
 }
-    
+
 @end
 
 
@@ -90,23 +90,22 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
 - (void)pluginInitialize
 {
     BOOL isiOS7 = (IsAtLeastiOSVersion(@"7.0"));
-                   
+
     // init
     NSNumber* uiviewControllerBasedStatusBarAppearance = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
     _uiviewControllerBasedStatusBarAppearance = (uiviewControllerBasedStatusBarAppearance == nil || [uiviewControllerBasedStatusBarAppearance boolValue]) && isiOS7;
-    
+
     // observe the statusBarHidden property
     [[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
-    
+
     _statusBarOverlaysWebView = YES; // default
-    
+
     [self initializeStatusBarBackgroundView];
 
-    [self styleLightContent:nil]; // match default backgroundColor of #000000
     self.viewController.view.autoresizesSubviews = YES;
-    
+
     NSString* setting;
-    
+
     setting  = @"StatusBarOverlaysWebView";
     if ([self settingForKey:setting]) {
         self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
@@ -116,6 +115,11 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     if ([self settingForKey:setting]) {
         [self _backgroundColorByHexString:[self settingForKey:setting]];
     }
+
+    setting  = @"StatusBarStyle";
+    if ([self settingForKey:setting]) {
+        [self setStatusBarStyle:[self settingForKey:setting]];
+    }
 }
 
 - (void) _ready:(CDVInvokedUrlCommand*)command
@@ -124,7 +128,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     [self.commandDelegate evalJs:[NSString stringWithFormat:@"StatusBar.isVisible = %@;", [UIApplication sharedApplication].statusBarHidden? @"false" : @"true" ]];
 }
 
-- (void) initializeStatusBarBackgroundView 
+- (void) initializeStatusBarBackgroundView
 {
     CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
     if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) {
@@ -146,9 +150,9 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     }
 
     CGRect bounds = [[UIScreen mainScreen] bounds];
-    
+
     if (statusBarOverlaysWebView) {
-        
+
         [_statusBarBackgroundView removeFromSuperview];
         if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) {
             self.webView.frame = CGRectMake(0, 0, bounds.size.height, bounds.size.width);
@@ -171,11 +175,11 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
             frame.origin.y = statusBarFrame.size.height;
             frame.size.height -= statusBarFrame.size.height;
         }
-        
+
         self.webView.frame = frame;
         [self.webView.superview addSubview:_statusBarBackgroundView];
     }
-    
+
     _statusBarOverlaysWebView = statusBarOverlaysWebView;
 }
 
@@ -190,7 +194,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     if (!([value isKindOfClass:[NSNumber class]])) {
         value = [NSNumber numberWithBool:YES];
     }
-    
+
     self.statusBarOverlaysWebView = [value boolValue];
 }
 
@@ -204,24 +208,24 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
 #pragma clang diagnostic pop
     }
 }
-    
+
 - (void) setStyleForStatusBar:(UIStatusBarStyle)style
 {
     if (_uiviewControllerBasedStatusBarAppearance) {
         CDVViewController* vc = (CDVViewController*)self.viewController;
         vc.sb_statusBarStyle = [NSNumber numberWithInt:style];
         [self refreshStatusBarAppearance];
-        
+
     } else {
         [[UIApplication sharedApplication] setStatusBarStyle:style];
     }
 }
-    
+
 - (void) setStatusBarStyle:(NSString*)statusBarStyle
 {
     // default, lightContent, blackTranslucent, blackOpaque
     NSString* lcStatusBarStyle = [statusBarStyle lowercaseString];
-    
+
     if ([lcStatusBarStyle isEqualToString:@"default"]) {
         [self styleDefault:nil];
     } else if ([lcStatusBarStyle isEqualToString:@"lightcontent"]) {
@@ -259,7 +263,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     if (!([value isKindOfClass:[NSString class]])) {
         value = @"black";
     }
-    
+
     SEL selector = NSSelectorFromString([value stringByAppendingString:@"Color"]);
     if ([UIColor respondsToSelector:selector]) {
         _statusBarBackgroundView.backgroundColor = [UIColor performSelector:selector];
@@ -272,7 +276,7 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     NSScanner* scanner = [NSScanner scannerWithString:hexString];
     [scanner setScanLocation:1];
     [scanner scanHexInt:&rgbValue];
-    
+
     _statusBarBackgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
     _statusBarBackgroundView.backgroundColor = _statusBarBackgroundColor;
 }
@@ -283,11 +287,11 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
     if (!([value isKindOfClass:[NSString class]])) {
         value = @"#000000";
     }
-    
+
     if (![value hasPrefix:@"#"] || [value length] < 7) {
         return;
     }
-    
+
     [self _backgroundColorByHexString:value];
 }
 
@@ -303,40 +307,40 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
         [app setStatusBarHidden:YES];
     }
 }
-    
+
 - (void) hide:(CDVInvokedUrlCommand*)command
 {
     UIApplication* app = [UIApplication sharedApplication];
-    
+
     if (!app.isStatusBarHidden)
     {
         self.viewController.wantsFullScreenLayout = YES;
         CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
-        
+
         [self hideStatusBar];
 
         if (IsAtLeastiOSVersion(@"7.0")) {
             [_statusBarBackgroundView removeFromSuperview];
         }
-        
+
         if (!_statusBarOverlaysWebView) {
-        
+
             CGRect frame = self.webView.frame;
             frame.origin.y = 0;
-        
+
             if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) {
                 frame.size.height += statusBarFrame.size.width;
             } else {
                 frame.size.height += statusBarFrame.size.height;
             }
-            
+
             self.webView.frame = frame;
         }
-        
+
         _statusBarBackgroundView.hidden = YES;
     }
 }
-    
+
 - (void) showStatusBar
 {
     if (_uiviewControllerBasedStatusBarAppearance) {
@@ -349,31 +353,31 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
         [app setStatusBarHidden:NO];
     }
 }
-    
+
 - (void) show:(CDVInvokedUrlCommand*)command
 {
     UIApplication* app = [UIApplication sharedApplication];
-    
+
     if (app.isStatusBarHidden)
     {
         BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));
         self.viewController.wantsFullScreenLayout = isIOS7;
-        
+
         [self showStatusBar];
-        
+
         if (isIOS7) {
             CGRect frame = self.webView.frame;
             self.viewController.view.frame = [[UIScreen mainScreen] bounds];
-            
+
             CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
-            
+
             if (!self.statusBarOverlaysWebView) {
-                
+
                 // 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
                 // statusBar's current size
                 CGRect sbBgFrame = _statusBarBackgroundView.frame;
-                
+
                 if (UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation)) {
                     frame.origin.y = statusBarFrame.size.width;
                     frame.size.height -= statusBarFrame.size.width;
@@ -383,19 +387,19 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
                     frame.size.height -= statusBarFrame.size.height;
                     sbBgFrame.size = statusBarFrame.size;
                 }
-                
+
                 _statusBarBackgroundView.frame = sbBgFrame;
                 [self.webView.superview addSubview:_statusBarBackgroundView];
             }
 
             self.webView.frame = frame;
-            
+
         } else {
-            
+
             CGRect bounds = [[UIScreen mainScreen] applicationFrame];
             self.viewController.view.frame = bounds;
         }
-        
+
         _statusBarBackgroundView.hidden = NO;
     }
 }