Skip to content

Commit c66eb49

Browse files
author
Andrew McCloud
committed
Initial implementation of StatusBarIOS module for issue #4
1 parent 41b0b58 commit c66eb49

File tree

10 files changed

+164
-0
lines changed

10 files changed

+164
-0
lines changed

Examples/Movies/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<array>
2929
<string>armv7</string>
3030
</array>
31+
<key>UIViewControllerBasedStatusBarAppearance</key>
32+
<false/>
3133
<key>UISupportedInterfaceOrientations</key>
3234
<array>
3335
<string>UIInterfaceOrientationPortrait</string>

Examples/TicTacToe/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<array>
2929
<string>armv7</string>
3030
</array>
31+
<key>UIViewControllerBasedStatusBarAppearance</key>
32+
<false/>
3133
<key>UISupportedInterfaceOrientations</key>
3234
<array>
3335
<string>UIInterfaceOrientationPortrait</string>

Examples/UIExplorer/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<array>
2929
<string>armv7</string>
3030
</array>
31+
<key>UIViewControllerBasedStatusBarAppearance</key>
32+
<false/>
3133
<key>UISupportedInterfaceOrientations</key>
3234
<array>
3335
<string>UIInterfaceOrientationPortrait</string>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @providesModule StatusBarIOSExample
3+
*/
4+
'use strict';
5+
6+
var React = require('react-native');
7+
var {
8+
StyleSheet,
9+
View,
10+
Text,
11+
TouchableHighlight,
12+
StatusBarIOS,
13+
} = React;
14+
15+
exports.framework = 'React';
16+
exports.title = 'StatusBarIOS';
17+
exports.description = 'Module for controlling iOS status bar';
18+
exports.examples = [{
19+
title: 'Status Bar Style',
20+
render() {
21+
return (
22+
<View>
23+
{Object.keys(StatusBarIOS.style).map((key) =>
24+
<TouchableHighlight style={styles.wrapper}
25+
onPress={() => StatusBarIOS.setStyle(StatusBarIOS.style[key])}>
26+
<View style={styles.button}>
27+
<Text>setStyle(StatusBarIOS.style.{key})</Text>
28+
</View>
29+
</TouchableHighlight>
30+
)}
31+
</View>
32+
);
33+
},
34+
}, {
35+
title: 'Status Bar Style Animated',
36+
render() {
37+
return (
38+
<View>
39+
{Object.keys(StatusBarIOS.style).map((key) =>
40+
<TouchableHighlight style={styles.wrapper}
41+
onPress={() => StatusBarIOS.setStyle(StatusBarIOS.style[key], true)}>
42+
<View style={styles.button}>
43+
<Text>setStyle(StatusBarIOS.style.{key}, true)</Text>
44+
</View>
45+
</TouchableHighlight>
46+
)}
47+
</View>
48+
);
49+
},
50+
}, {
51+
title: 'Status Bar Hidden',
52+
render() {
53+
return (
54+
<View>
55+
{Object.keys(StatusBarIOS.animation).map((key) =>
56+
<View>
57+
<TouchableHighlight style={styles.wrapper}
58+
onPress={() => StatusBarIOS.setHidden(true, StatusBarIOS.animation[key])}>
59+
<View style={styles.button}>
60+
<Text>setHidden(true, StatusBarIOS.animation.{key})</Text>
61+
</View>
62+
</TouchableHighlight>
63+
<TouchableHighlight style={styles.wrapper}
64+
onPress={() => StatusBarIOS.setHidden(false, StatusBarIOS.animation[key])}>
65+
<View style={styles.button}>
66+
<Text>setHidden(false, StatusBarIOS.animation.{key})</Text>
67+
</View>
68+
</TouchableHighlight>
69+
</View>
70+
)}
71+
</View>
72+
);
73+
},
74+
}];
75+
76+
var styles = StyleSheet.create({
77+
wrapper: {
78+
borderRadius: 5,
79+
marginBottom: 5,
80+
},
81+
button: {
82+
backgroundColor: '#eeeeee',
83+
padding: 10,
84+
},
85+
});
86+

Examples/UIExplorer/UIExplorerList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var EXAMPLES = [
2525
require('./ImageExample'),
2626
require('./ListViewSimpleExample'),
2727
require('./NavigatorIOSExample'),
28+
require('./StatusBarIOSExample'),
2829
require('./PointerEventsExample'),
2930
require('./TouchableExample'),
3031
require('./SpinnerExample'),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @providesModule StatusBarIOS
3+
*/
4+
'use strict';
5+
6+
var { RCTStatusBarManager } = require('NativeModules');
7+
8+
var StatusBarIOS = {
9+
style: {
10+
default: 0,
11+
lightContent: 1,
12+
},
13+
14+
animation: {
15+
none: 0,
16+
fade: 1,
17+
slide: 2,
18+
},
19+
20+
setStyle(style, animated) {
21+
animated = animated || false;
22+
RCTStatusBarManager.setStatusBarStyle(style, animated);
23+
},
24+
25+
setHidden(hidden, animation) {
26+
animation = animation || StatusBarIOS.animation.none;
27+
RCTStatusBarManager.setStatusBarHidden(hidden, animation);
28+
},
29+
};
30+
31+
module.exports = StatusBarIOS;

Libraries/react-native/react-native.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Image = require('Image');
1111
var ListView = require('ListView');
1212
var ListViewDataSource = require('ListViewDataSource');
1313
var NavigatorIOS = require('NavigatorIOS');
14+
var StatusBarIOS = require('StatusBarIOS');
1415
var PixelRatio = require('PixelRatio');
1516
var React = require('React');
1617
var ScrollView = require('ScrollView');
@@ -34,6 +35,7 @@ var ReactNative = {
3435
ListView,
3536
ListViewDataSource,
3637
NavigatorIOS,
38+
StatusBarIOS,
3739
PixelRatio,
3840
ScrollView,
3941
SpinnerIOS,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <UIKit/UIKit.h>
2+
3+
#import "RCTExport.h"
4+
5+
@interface RCTStatusBarManager : NSObject <RCTNativeModule>
6+
7+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#import "RCTStatusBarManager.h"
2+
3+
@implementation RCTStatusBarManager
4+
5+
- (void)setStatusBarStyle:(NSNumber *)statusBarStyle animated:(NSNumber *)animated {
6+
RCT_EXPORT();
7+
8+
dispatch_async(dispatch_get_main_queue(), ^{
9+
[[UIApplication sharedApplication]
10+
setStatusBarStyle:[statusBarStyle intValue]
11+
animated:[animated boolValue]];
12+
});
13+
}
14+
15+
- (void)setStatusBarHidden:(NSNumber *)hidden withAnimation:(NSNumber *)animation {
16+
RCT_EXPORT();
17+
18+
dispatch_async(dispatch_get_main_queue(), ^{
19+
[[UIApplication sharedApplication]
20+
setStatusBarHidden:[hidden boolValue]
21+
withAnimation:[animation intValue]];
22+
});
23+
}
24+
25+
@end

ReactKit/ReactKit.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
13E067571A70F44B002CDEE1 /* RCTView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067501A70F44B002CDEE1 /* RCTView.m */; };
4343
13E067581A70F44B002CDEE1 /* RCTViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067521A70F44B002CDEE1 /* RCTViewManager.m */; };
4444
13E067591A70F44B002CDEE1 /* UIView+ReactKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067541A70F44B002CDEE1 /* UIView+ReactKit.m */; };
45+
396767821A7C247E003BFF0E /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 396767811A7C247E003BFF0E /* RCTStatusBarManager.m */; };
4546
830A229E1A66C68A008503DA /* RCTRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 830A229D1A66C68A008503DA /* RCTRootView.m */; };
4647
832348161A77A5AA00B55238 /* Layout.c in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FC71A68125100A75B9A /* Layout.c */; };
4748
83CBBA511A601E3B00E9B192 /* RCTAssert.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CBBA4B1A601E3B00E9B192 /* RCTAssert.m */; };
@@ -142,6 +143,8 @@
142143
13E067521A70F44B002CDEE1 /* RCTViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTViewManager.m; sourceTree = "<group>"; };
143144
13E067531A70F44B002CDEE1 /* UIView+ReactKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ReactKit.h"; sourceTree = "<group>"; };
144145
13E067541A70F44B002CDEE1 /* UIView+ReactKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+ReactKit.m"; sourceTree = "<group>"; };
146+
396767801A7C247E003BFF0E /* RCTStatusBarManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTStatusBarManager.h; sourceTree = "<group>"; };
147+
396767811A7C247E003BFF0E /* RCTStatusBarManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTStatusBarManager.m; sourceTree = "<group>"; };
145148
830213F31A654E0800B993E6 /* RCTExport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTExport.h; sourceTree = "<group>"; };
146149
830213F41A65574D00B993E6 /* RCTExport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTExport.m; sourceTree = "<group>"; };
147150
830A229C1A66C68A008503DA /* RCTRootView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRootView.h; sourceTree = "<group>"; };
@@ -225,6 +228,8 @@
225228
13B07FEE1A69327A00A75B9A /* RCTTiming.m */,
226229
13E067481A70F434002CDEE1 /* RCTUIManager.h */,
227230
13E067491A70F434002CDEE1 /* RCTUIManager.m */,
231+
396767801A7C247E003BFF0E /* RCTStatusBarManager.h */,
232+
396767811A7C247E003BFF0E /* RCTStatusBarManager.m */,
228233
);
229234
path = Modules;
230235
sourceTree = "<group>";
@@ -474,6 +479,7 @@
474479
83CBBA871A60202500E9B192 /* RCTJavaScriptAppEngine.m in Sources */,
475480
134FCB3E1A6E7F0800051CC8 /* RCTWebViewExecutor.m in Sources */,
476481
83EEC2EE1A604AB200C39218 /* RCTModuleMethod.m in Sources */,
482+
396767821A7C247E003BFF0E /* RCTStatusBarManager.m in Sources */,
477483
13B0801C1A69489C00A75B9A /* RCTNavItem.m in Sources */,
478484
137029331A69659C00575408 /* RCTExport.m in Sources */,
479485
83CBBA691A601EF300E9B192 /* RCTJavaScriptEventDispatcher.m in Sources */,

0 commit comments

Comments
 (0)