From c66eb49f1b2210ac2f75ef1e80b61de85df16be3 Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Fri, 30 Jan 2015 14:23:38 -0800 Subject: [PATCH] Initial implementation of StatusBarIOS module for issue #4 --- Examples/Movies/Info.plist | 2 + Examples/TicTacToe/Info.plist | 2 + Examples/UIExplorer/Info.plist | 2 + Examples/UIExplorer/StatusBarIOSExample.js | 86 +++++++++++++++++++ Examples/UIExplorer/UIExplorerList.js | 1 + .../Components/StatusBar/StatusBarIOS.ios.js | 31 +++++++ Libraries/react-native/react-native.js | 2 + ReactKit/Modules/RCTStatusBarManager.h | 7 ++ ReactKit/Modules/RCTStatusBarManager.m | 25 ++++++ ReactKit/ReactKit.xcodeproj/project.pbxproj | 6 ++ 10 files changed, 164 insertions(+) create mode 100644 Examples/UIExplorer/StatusBarIOSExample.js create mode 100644 Libraries/Components/StatusBar/StatusBarIOS.ios.js create mode 100644 ReactKit/Modules/RCTStatusBarManager.h create mode 100644 ReactKit/Modules/RCTStatusBarManager.m diff --git a/Examples/Movies/Info.plist b/Examples/Movies/Info.plist index 1c298405ac3722..3c7e8c72e4aea1 100644 --- a/Examples/Movies/Info.plist +++ b/Examples/Movies/Info.plist @@ -28,6 +28,8 @@ armv7 + UIViewControllerBasedStatusBarAppearance + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/Examples/TicTacToe/Info.plist b/Examples/TicTacToe/Info.plist index 1c298405ac3722..3c7e8c72e4aea1 100644 --- a/Examples/TicTacToe/Info.plist +++ b/Examples/TicTacToe/Info.plist @@ -28,6 +28,8 @@ armv7 + UIViewControllerBasedStatusBarAppearance + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/Examples/UIExplorer/Info.plist b/Examples/UIExplorer/Info.plist index 1c298405ac3722..3c7e8c72e4aea1 100644 --- a/Examples/UIExplorer/Info.plist +++ b/Examples/UIExplorer/Info.plist @@ -28,6 +28,8 @@ armv7 + UIViewControllerBasedStatusBarAppearance + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/Examples/UIExplorer/StatusBarIOSExample.js b/Examples/UIExplorer/StatusBarIOSExample.js new file mode 100644 index 00000000000000..0c0ff567fac0a5 --- /dev/null +++ b/Examples/UIExplorer/StatusBarIOSExample.js @@ -0,0 +1,86 @@ +/** + * @providesModule StatusBarIOSExample + */ +'use strict'; + +var React = require('react-native'); +var { + StyleSheet, + View, + Text, + TouchableHighlight, + StatusBarIOS, +} = React; + +exports.framework = 'React'; +exports.title = 'StatusBarIOS'; +exports.description = 'Module for controlling iOS status bar'; +exports.examples = [{ + title: 'Status Bar Style', + render() { + return ( + + {Object.keys(StatusBarIOS.style).map((key) => + StatusBarIOS.setStyle(StatusBarIOS.style[key])}> + + setStyle(StatusBarIOS.style.{key}) + + + )} + + ); + }, +}, { + title: 'Status Bar Style Animated', + render() { + return ( + + {Object.keys(StatusBarIOS.style).map((key) => + StatusBarIOS.setStyle(StatusBarIOS.style[key], true)}> + + setStyle(StatusBarIOS.style.{key}, true) + + + )} + + ); + }, +}, { + title: 'Status Bar Hidden', + render() { + return ( + + {Object.keys(StatusBarIOS.animation).map((key) => + + StatusBarIOS.setHidden(true, StatusBarIOS.animation[key])}> + + setHidden(true, StatusBarIOS.animation.{key}) + + + StatusBarIOS.setHidden(false, StatusBarIOS.animation[key])}> + + setHidden(false, StatusBarIOS.animation.{key}) + + + + )} + + ); + }, +}]; + +var styles = StyleSheet.create({ + wrapper: { + borderRadius: 5, + marginBottom: 5, + }, + button: { + backgroundColor: '#eeeeee', + padding: 10, + }, +}); + diff --git a/Examples/UIExplorer/UIExplorerList.js b/Examples/UIExplorer/UIExplorerList.js index 207ad2d66b8d0b..9effbf8e46da14 100644 --- a/Examples/UIExplorer/UIExplorerList.js +++ b/Examples/UIExplorer/UIExplorerList.js @@ -25,6 +25,7 @@ var EXAMPLES = [ require('./ImageExample'), require('./ListViewSimpleExample'), require('./NavigatorIOSExample'), + require('./StatusBarIOSExample'), require('./PointerEventsExample'), require('./TouchableExample'), require('./SpinnerExample'), diff --git a/Libraries/Components/StatusBar/StatusBarIOS.ios.js b/Libraries/Components/StatusBar/StatusBarIOS.ios.js new file mode 100644 index 00000000000000..6495d5afbf3dd0 --- /dev/null +++ b/Libraries/Components/StatusBar/StatusBarIOS.ios.js @@ -0,0 +1,31 @@ +/** + * @providesModule StatusBarIOS + */ +'use strict'; + +var { RCTStatusBarManager } = require('NativeModules'); + +var StatusBarIOS = { + style: { + default: 0, + lightContent: 1, + }, + + animation: { + none: 0, + fade: 1, + slide: 2, + }, + + setStyle(style, animated) { + animated = animated || false; + RCTStatusBarManager.setStatusBarStyle(style, animated); + }, + + setHidden(hidden, animation) { + animation = animation || StatusBarIOS.animation.none; + RCTStatusBarManager.setStatusBarHidden(hidden, animation); + }, +}; + +module.exports = StatusBarIOS; diff --git a/Libraries/react-native/react-native.js b/Libraries/react-native/react-native.js index 12a82fefaee4b5..b483534e1825b9 100644 --- a/Libraries/react-native/react-native.js +++ b/Libraries/react-native/react-native.js @@ -11,6 +11,7 @@ var Image = require('Image'); var ListView = require('ListView'); var ListViewDataSource = require('ListViewDataSource'); var NavigatorIOS = require('NavigatorIOS'); +var StatusBarIOS = require('StatusBarIOS'); var PixelRatio = require('PixelRatio'); var React = require('React'); var ScrollView = require('ScrollView'); @@ -34,6 +35,7 @@ var ReactNative = { ListView, ListViewDataSource, NavigatorIOS, + StatusBarIOS, PixelRatio, ScrollView, SpinnerIOS, diff --git a/ReactKit/Modules/RCTStatusBarManager.h b/ReactKit/Modules/RCTStatusBarManager.h new file mode 100644 index 00000000000000..97fd45d4271442 --- /dev/null +++ b/ReactKit/Modules/RCTStatusBarManager.h @@ -0,0 +1,7 @@ +#import + +#import "RCTExport.h" + +@interface RCTStatusBarManager : NSObject + +@end diff --git a/ReactKit/Modules/RCTStatusBarManager.m b/ReactKit/Modules/RCTStatusBarManager.m new file mode 100644 index 00000000000000..168be8d7ee766d --- /dev/null +++ b/ReactKit/Modules/RCTStatusBarManager.m @@ -0,0 +1,25 @@ +#import "RCTStatusBarManager.h" + +@implementation RCTStatusBarManager + +- (void)setStatusBarStyle:(NSNumber *)statusBarStyle animated:(NSNumber *)animated { + RCT_EXPORT(); + + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] + setStatusBarStyle:[statusBarStyle intValue] + animated:[animated boolValue]]; + }); +} + +- (void)setStatusBarHidden:(NSNumber *)hidden withAnimation:(NSNumber *)animation { + RCT_EXPORT(); + + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] + setStatusBarHidden:[hidden boolValue] + withAnimation:[animation intValue]]; + }); +} + +@end diff --git a/ReactKit/ReactKit.xcodeproj/project.pbxproj b/ReactKit/ReactKit.xcodeproj/project.pbxproj index 286dc278abd64e..a2579294a4989e 100644 --- a/ReactKit/ReactKit.xcodeproj/project.pbxproj +++ b/ReactKit/ReactKit.xcodeproj/project.pbxproj @@ -42,6 +42,7 @@ 13E067571A70F44B002CDEE1 /* RCTView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067501A70F44B002CDEE1 /* RCTView.m */; }; 13E067581A70F44B002CDEE1 /* RCTViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067521A70F44B002CDEE1 /* RCTViewManager.m */; }; 13E067591A70F44B002CDEE1 /* UIView+ReactKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067541A70F44B002CDEE1 /* UIView+ReactKit.m */; }; + 396767821A7C247E003BFF0E /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 396767811A7C247E003BFF0E /* RCTStatusBarManager.m */; }; 830A229E1A66C68A008503DA /* RCTRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 830A229D1A66C68A008503DA /* RCTRootView.m */; }; 832348161A77A5AA00B55238 /* Layout.c in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FC71A68125100A75B9A /* Layout.c */; }; 83CBBA511A601E3B00E9B192 /* RCTAssert.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CBBA4B1A601E3B00E9B192 /* RCTAssert.m */; }; @@ -142,6 +143,8 @@ 13E067521A70F44B002CDEE1 /* RCTViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTViewManager.m; sourceTree = ""; }; 13E067531A70F44B002CDEE1 /* UIView+ReactKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ReactKit.h"; sourceTree = ""; }; 13E067541A70F44B002CDEE1 /* UIView+ReactKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+ReactKit.m"; sourceTree = ""; }; + 396767801A7C247E003BFF0E /* RCTStatusBarManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTStatusBarManager.h; sourceTree = ""; }; + 396767811A7C247E003BFF0E /* RCTStatusBarManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTStatusBarManager.m; sourceTree = ""; }; 830213F31A654E0800B993E6 /* RCTExport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTExport.h; sourceTree = ""; }; 830213F41A65574D00B993E6 /* RCTExport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTExport.m; sourceTree = ""; }; 830A229C1A66C68A008503DA /* RCTRootView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootView.h; sourceTree = ""; }; @@ -225,6 +228,8 @@ 13B07FEE1A69327A00A75B9A /* RCTTiming.m */, 13E067481A70F434002CDEE1 /* RCTUIManager.h */, 13E067491A70F434002CDEE1 /* RCTUIManager.m */, + 396767801A7C247E003BFF0E /* RCTStatusBarManager.h */, + 396767811A7C247E003BFF0E /* RCTStatusBarManager.m */, ); path = Modules; sourceTree = ""; @@ -474,6 +479,7 @@ 83CBBA871A60202500E9B192 /* RCTJavaScriptAppEngine.m in Sources */, 134FCB3E1A6E7F0800051CC8 /* RCTWebViewExecutor.m in Sources */, 83EEC2EE1A604AB200C39218 /* RCTModuleMethod.m in Sources */, + 396767821A7C247E003BFF0E /* RCTStatusBarManager.m in Sources */, 13B0801C1A69489C00A75B9A /* RCTNavItem.m in Sources */, 137029331A69659C00575408 /* RCTExport.m in Sources */, 83CBBA691A601EF300E9B192 /* RCTJavaScriptEventDispatcher.m in Sources */,