1414#if !TARGET_OS_TV
1515@implementation RCTConvert (UIStatusBar)
1616
17- RCT_ENUM_CONVERTER (UIStatusBarStyle, (@{
18- @" default" : @(UIStatusBarStyleDefault),
19- @" light-content" : @(UIStatusBarStyleLightContent),
20- @" dark-content" : @(UIStatusBarStyleDefault),
21- }), UIStatusBarStyleDefault, integerValue);
22-
23- RCT_ENUM_CONVERTER (UIStatusBarAnimation, (@{
24- @" none" : @(UIStatusBarAnimationNone),
25- @" fade" : @(UIStatusBarAnimationFade),
26- @" slide" : @(UIStatusBarAnimationSlide),
27- }), UIStatusBarAnimationNone, integerValue);
17+ + (UIStatusBarStyle)UIStatusBarStyle : (id )json RCT_DYNAMIC
18+ {
19+ static NSDictionary *mapping;
20+ static dispatch_once_t onceToken;
21+ dispatch_once (&onceToken, ^{
22+ if (@available (iOS 13.0 , *)) {
23+ mapping = @{
24+ @" default" : @(UIStatusBarStyleDefault),
25+ @" light-content" : @(UIStatusBarStyleLightContent),
26+ #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
27+ __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
28+ @" dark-content" : @(UIStatusBarStyleDarkContent)
29+ #else
30+ @" dark-content" : @(UIStatusBarStyleDefault)
31+ #endif
32+ };
33+
34+ } else {
35+ mapping = @{
36+ @" default" : @(UIStatusBarStyleDefault),
37+ @" light-content" : @(UIStatusBarStyleLightContent),
38+ @" dark-content" : @(UIStatusBarStyleDefault)
39+ };
40+ }
41+ });
42+ return _RCT_CAST (
43+ type, [RCTConvertEnumValue (" UIStatusBarStyle" , mapping, @(UIStatusBarStyleDefault), json) integerValue ]);
44+ }
45+
46+ RCT_ENUM_CONVERTER (
47+ UIStatusBarAnimation,
48+ (@{
49+ @" none" : @(UIStatusBarAnimationNone),
50+ @" fade" : @(UIStatusBarAnimationFade),
51+ @" slide" : @(UIStatusBarAnimationSlide),
52+ }),
53+ UIStatusBarAnimationNone,
54+ integerValue);
2855
2956@end
3057#endif
@@ -36,8 +63,9 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
3663 static BOOL value;
3764 static dispatch_once_t onceToken;
3865 dispatch_once (&onceToken, ^{
39- value = [[[NSBundle mainBundle ] objectForInfoDictionaryKey:
40- @" UIViewControllerBasedStatusBarAppearance" ] ?: @YES boolValue ];
66+ value =
67+ [[[NSBundle mainBundle ] objectForInfoDictionaryKey: @" UIViewControllerBasedStatusBarAppearance" ]
68+ ?: @YES boolValue ];
4169 });
4270
4371 return value;
@@ -47,17 +75,22 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
4775
4876- (NSArray <NSString *> *)supportedEvents
4977{
50- return @[@" statusBarFrameDidChange" ,
51- @" statusBarFrameWillChange" ];
78+ return @[ @" statusBarFrameDidChange" , @" statusBarFrameWillChange" ];
5279}
5380
5481#if !TARGET_OS_TV
5582
5683- (void )startObserving
5784{
5885 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter ];
59- [nc addObserver: self selector: @selector (applicationDidChangeStatusBarFrame: ) name: UIApplicationDidChangeStatusBarFrameNotification object: nil ];
60- [nc addObserver: self selector: @selector (applicationWillChangeStatusBarFrame: ) name: UIApplicationWillChangeStatusBarFrameNotification object: nil ];
86+ [nc addObserver: self
87+ selector: @selector (applicationDidChangeStatusBarFrame: )
88+ name: UIApplicationDidChangeStatusBarFrameNotification
89+ object: nil ];
90+ [nc addObserver: self
91+ selector: @selector (applicationWillChangeStatusBarFrame: )
92+ name: UIApplicationWillChangeStatusBarFrameNotification
93+ object: nil ];
6194}
6295
6396- (void )stopObserving
@@ -74,11 +107,11 @@ - (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notifi
74107{
75108 CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue ];
76109 NSDictionary *event = @{
77- @" frame" : @{
78- @" x" : @(frame.origin .x ),
79- @" y" : @(frame.origin .y ),
80- @" width" : @(frame.size .width ),
81- @" height" : @(frame.size .height ),
110+ @" frame" : @{
111+ @" x" : @(frame.origin .x ),
112+ @" y" : @(frame.origin .y ),
113+ @" width" : @(frame.size .width ),
114+ @" height" : @(frame.size .height ),
82115 },
83116 };
84117 [self sendEventWithName: eventName body: event];
@@ -94,48 +127,44 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
94127 [self emitEvent: @" statusBarFrameWillChange" forNotification: notification];
95128}
96129
97- RCT_EXPORT_METHOD (getHeight: (RCTResponseSenderBlock)callback)
130+ RCT_EXPORT_METHOD (getHeight : (RCTResponseSenderBlock)callback)
98131{
99- callback (@[@{
100- @" height" : @(RCTSharedApplication ().statusBarFrame .size .height ),
101- }]);
132+ callback (@[ @{
133+ @" height" : @(RCTSharedApplication ().statusBarFrame .size .height ),
134+ } ]);
102135}
103136
104- RCT_EXPORT_METHOD (setStyle:(UIStatusBarStyle)statusBarStyle
105- animated:(BOOL )animated)
137+ RCT_EXPORT_METHOD (setStyle : (UIStatusBarStyle)statusBarStyle animated : (BOOL )animated)
106138{
107139 if (RCTViewControllerBasedStatusBarAppearance ()) {
108140 RCTLogError (@" RCTStatusBarManager module requires that the \
109141 UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO" );
110142 } else {
111143#pragma clang diagnostic push
112144#pragma clang diagnostic ignored "-Wdeprecated-declarations"
113- [RCTSharedApplication () setStatusBarStyle: statusBarStyle
114- animated: animated];
145+ [RCTSharedApplication () setStatusBarStyle: statusBarStyle animated: animated];
115146 }
116147#pragma clang diagnostic pop
117148}
118149
119- RCT_EXPORT_METHOD (setHidden:(BOOL )hidden
120- withAnimation:(UIStatusBarAnimation)animation)
150+ RCT_EXPORT_METHOD (setHidden : (BOOL )hidden withAnimation : (UIStatusBarAnimation)animation)
121151{
122152 if (RCTViewControllerBasedStatusBarAppearance ()) {
123153 RCTLogError (@" RCTStatusBarManager module requires that the \
124154 UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO" );
125155 } else {
126156#pragma clang diagnostic push
127157#pragma clang diagnostic ignored "-Wdeprecated-declarations"
128- [RCTSharedApplication () setStatusBarHidden: hidden
129- withAnimation: animation];
158+ [RCTSharedApplication () setStatusBarHidden: hidden withAnimation: animation];
130159#pragma clang diagnostic pop
131160 }
132161}
133162
134- RCT_EXPORT_METHOD (setNetworkActivityIndicatorVisible: (BOOL )visible)
163+ RCT_EXPORT_METHOD (setNetworkActivityIndicatorVisible : (BOOL )visible)
135164{
136165 RCTSharedApplication ().networkActivityIndicatorVisible = visible;
137166}
138167
139- #endif // TARGET_OS_TV
168+ #endif // TARGET_OS_TV
140169
141170@end
0 commit comments