Skip to content

Commit 31bcafb

Browse files
committed
2015-02-06 updates
- [ReactServer] Fix graph update | Amjad Masad - Added RCTStatusBarManager module | Nick Lockwood
1 parent 4f613e2 commit 31bcafb

File tree

11 files changed

+231
-10
lines changed

11 files changed

+231
-10
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
@@ -34,5 +34,7 @@
3434
<string>UIInterfaceOrientationLandscapeLeft</string>
3535
<string>UIInterfaceOrientationLandscapeRight</string>
3636
</array>
37+
<key>UIViewControllerBasedStatusBarAppearance</key>
38+
<false/>
3739
</dict>
3840
</plist>

Examples/UIExplorer/Info.plist

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

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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2004-present Facebook. All Rights Reserved.
3+
*
4+
* @providesModule StatusBarIOS
5+
* @flow
6+
*/
7+
'use strict';
8+
9+
var { RKStatusBarManager } = require('NativeModules');
10+
11+
var StatusBarIOS = {
12+
13+
Style: {
14+
default: RKStatusBarManager.Style.default,
15+
lightContent: RKStatusBarManager.Style.lightContent
16+
},
17+
18+
Animation: {
19+
none: RKStatusBarManager.Animation.none,
20+
fade: RKStatusBarManager.Animation.fade,
21+
slide: RKStatusBarManager.Animation.slide,
22+
},
23+
24+
setStyle(style: number, animated: boolean) {
25+
animated = animated || false;
26+
RKStatusBarManager.setStyle(style, animated);
27+
},
28+
29+
setHidden(hidden: boolean, animation: number) {
30+
animation = animation || StatusBarIOS.Animation.none;
31+
RKStatusBarManager.setHidden(hidden, animation);
32+
},
33+
};
34+
35+
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
#import <UIKit/UIKit.h>
4+
5+
#import "RCTBridgeModule.h"
6+
7+
@interface RCTStatusBarManager : NSObject <RCTBridgeModule>
8+
9+
@end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
#import "RCTStatusBarManager.h"
4+
5+
#import "RCTLog.h"
6+
7+
@implementation RCTStatusBarManager
8+
9+
static BOOL RCTViewControllerBasedStatusBarAppearance()
10+
{
11+
static BOOL value;
12+
static dispatch_once_t onceToken;
13+
dispatch_once(&onceToken, ^{
14+
value = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue];
15+
});
16+
17+
return value;
18+
}
19+
20+
- (void)setStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated
21+
{
22+
RCT_EXPORT();
23+
24+
dispatch_async(dispatch_get_main_queue(), ^{
25+
26+
if (RCTViewControllerBasedStatusBarAppearance()) {
27+
RCTLogError(@"RCTStatusBarManager module requires that the \
28+
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
29+
} else {
30+
[[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle
31+
animated:animated];
32+
}
33+
});
34+
}
35+
36+
- (void)setHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
37+
{
38+
RCT_EXPORT();
39+
40+
dispatch_async(dispatch_get_main_queue(), ^{
41+
42+
if (RCTViewControllerBasedStatusBarAppearance()) {
43+
RCTLogError(@"RCTStatusBarManager module requires that the \
44+
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
45+
} else {
46+
[[UIApplication sharedApplication] setStatusBarHidden:hidden
47+
withAnimation:animation];
48+
}
49+
});
50+
}
51+
52+
+ (NSDictionary *)constantsToExport
53+
{
54+
return @{
55+
@"Style": @{
56+
@"default": @(UIStatusBarStyleDefault),
57+
@"lightContent": @(UIStatusBarStyleLightContent),
58+
},
59+
@"Animation": @{
60+
@"none": @(UIStatusBarAnimationNone),
61+
@"fade": @(UIStatusBarAnimationFade),
62+
@"slide": @(UIStatusBarAnimationSlide),
63+
},
64+
};
65+
}
66+
67+
@end

ReactKit/ReactKit.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
137029491A698FF000575408 /* RCTNetworkImageViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 137029401A698FF000575408 /* RCTNetworkImageViewManager.m */; };
1717
137029501A6990A100575408 /* RCTNetworkImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1370294F1A6990A100575408 /* RCTNetworkImageView.m */; };
1818
137029531A69923600575408 /* RCTImageDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 137029521A69923600575408 /* RCTImageDownloader.m */; };
19+
13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */; };
1920
13A1F71E1A75392D00D3D453 /* RCTKeyCommands.m in Sources */ = {isa = PBXBuildFile; fileRef = 13A1F71D1A75392D00D3D453 /* RCTKeyCommands.m */; };
2021
13B07FEF1A69327A00A75B9A /* RCTAlertManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FE81A69327A00A75B9A /* RCTAlertManager.m */; };
2122
13B07FF01A69327A00A75B9A /* RCTExceptionsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FEA1A69327A00A75B9A /* RCTExceptionsManager.m */; };
@@ -82,6 +83,8 @@
8283
137029521A69923600575408 /* RCTImageDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageDownloader.m; sourceTree = "<group>"; };
8384
137029571A6C197000575408 /* RCTRawTextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRawTextManager.h; sourceTree = "<group>"; };
8485
137029581A6C197000575408 /* RCTRawTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRawTextManager.m; sourceTree = "<group>"; };
86+
13723B4E1A82FD3C00F88898 /* RCTStatusBarManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTStatusBarManager.h; sourceTree = "<group>"; };
87+
13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTStatusBarManager.m; sourceTree = "<group>"; };
8588
13A1F71C1A75392D00D3D453 /* RCTKeyCommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTKeyCommands.h; sourceTree = "<group>"; };
8689
13A1F71D1A75392D00D3D453 /* RCTKeyCommands.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTKeyCommands.m; sourceTree = "<group>"; };
8790
13B07FC71A68125100A75B9A /* Layout.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Layout.c; sourceTree = "<group>"; };
@@ -206,6 +209,8 @@
206209
13B07FEE1A69327A00A75B9A /* RCTTiming.m */,
207210
13E067481A70F434002CDEE1 /* RCTUIManager.h */,
208211
13E067491A70F434002CDEE1 /* RCTUIManager.m */,
212+
13723B4E1A82FD3C00F88898 /* RCTStatusBarManager.h */,
213+
13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */,
209214
);
210215
path = Modules;
211216
sourceTree = "<group>";
@@ -403,6 +408,7 @@
403408
isa = PBXSourcesBuildPhase;
404409
buildActionMask = 2147483647;
405410
files = (
411+
13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */,
406412
13B0801E1A69489C00A75B9A /* RCTTextField.m in Sources */,
407413
13B07FEF1A69327A00A75B9A /* RCTAlertManager.m in Sources */,
408414
83CBBACC1A6023D300E9B192 /* RCTConvert.m in Sources */,

packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,26 @@ DependecyGraph.prototype._lookupName = function(modulePath) {
325325
}
326326
};
327327

328+
DependecyGraph.prototype._deleteModule = function(module) {
329+
delete this._graph[module.path];
330+
331+
// Others may keep a reference so we mark it as deleted.
332+
module.deleted = true;
333+
334+
// Haste allows different module to have the same id.
335+
if (this._moduleById[module.id] === module) {
336+
delete this._moduleById[module.id];
337+
}
338+
};
339+
328340
/**
329-
* Update the graph and idices with the module.
341+
* Update the graph and indices with the module.
330342
*/
331343
DependecyGraph.prototype._updateGraphWithModule = function(module) {
344+
if (this._graph[module.path]) {
345+
this._deleteModule(this._graph[module.path]);
346+
}
347+
332348
this._graph[module.path] = module;
333349

334350
if (this._moduleById[module.id]) {
@@ -389,15 +405,7 @@ DependecyGraph.prototype._processFileChange = function(eventType, filePath, root
389405
return;
390406
}
391407

392-
delete this._graph[module];
393-
394-
// Others may keep a reference so we mark it as deleted.
395-
module.deleted = true;
396-
397-
// Modules may have same id.
398-
if (this._moduleById[module.id] === module) {
399-
delete this._moduleById[module.id];
400-
}
408+
this._deleteModule(module);
401409
} else if (!(stat && stat.isDirectory())) {
402410
var self = this;
403411
this._loading = this._loading.then(function() {

0 commit comments

Comments
 (0)