14
14
#if !TARGET_OS_TV
15
15
@implementation RCTConvert (UIStatusBar)
16
16
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);
28
55
29
56
@end
30
57
#endif
@@ -36,8 +63,9 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
36
63
static BOOL value;
37
64
static dispatch_once_t onceToken;
38
65
dispatch_once (&onceToken, ^{
39
- value = [[[NSBundle mainBundle ] objectForInfoDictionaryKey:
40
- @" UIViewControllerBasedStatusBarAppearance" ] ?: @YES boolValue ];
66
+ value =
67
+ [[[NSBundle mainBundle ] objectForInfoDictionaryKey: @" UIViewControllerBasedStatusBarAppearance" ]
68
+ ?: @YES boolValue ];
41
69
});
42
70
43
71
return value;
@@ -47,17 +75,22 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
47
75
48
76
- (NSArray <NSString *> *)supportedEvents
49
77
{
50
- return @[@" statusBarFrameDidChange" ,
51
- @" statusBarFrameWillChange" ];
78
+ return @[ @" statusBarFrameDidChange" , @" statusBarFrameWillChange" ];
52
79
}
53
80
54
81
#if !TARGET_OS_TV
55
82
56
83
- (void )startObserving
57
84
{
58
85
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 ];
61
94
}
62
95
63
96
- (void )stopObserving
@@ -74,11 +107,11 @@ - (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notifi
74
107
{
75
108
CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue ];
76
109
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 ),
82
115
},
83
116
};
84
117
[self sendEventWithName: eventName body: event];
@@ -94,48 +127,44 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
94
127
[self emitEvent: @" statusBarFrameWillChange" forNotification: notification];
95
128
}
96
129
97
- RCT_EXPORT_METHOD (getHeight: (RCTResponseSenderBlock)callback)
130
+ RCT_EXPORT_METHOD (getHeight : (RCTResponseSenderBlock)callback)
98
131
{
99
- callback (@[@{
100
- @" height" : @(RCTSharedApplication ().statusBarFrame .size .height ),
101
- }]);
132
+ callback (@[ @{
133
+ @" height" : @(RCTSharedApplication ().statusBarFrame .size .height ),
134
+ } ]);
102
135
}
103
136
104
- RCT_EXPORT_METHOD (setStyle:(UIStatusBarStyle)statusBarStyle
105
- animated:(BOOL )animated)
137
+ RCT_EXPORT_METHOD (setStyle : (UIStatusBarStyle)statusBarStyle animated : (BOOL )animated)
106
138
{
107
139
if (RCTViewControllerBasedStatusBarAppearance ()) {
108
140
RCTLogError (@" RCTStatusBarManager module requires that the \
109
141
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO" );
110
142
} else {
111
143
#pragma clang diagnostic push
112
144
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
113
- [RCTSharedApplication () setStatusBarStyle: statusBarStyle
114
- animated: animated];
145
+ [RCTSharedApplication () setStatusBarStyle: statusBarStyle animated: animated];
115
146
}
116
147
#pragma clang diagnostic pop
117
148
}
118
149
119
- RCT_EXPORT_METHOD (setHidden:(BOOL )hidden
120
- withAnimation:(UIStatusBarAnimation)animation)
150
+ RCT_EXPORT_METHOD (setHidden : (BOOL )hidden withAnimation : (UIStatusBarAnimation)animation)
121
151
{
122
152
if (RCTViewControllerBasedStatusBarAppearance ()) {
123
153
RCTLogError (@" RCTStatusBarManager module requires that the \
124
154
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO" );
125
155
} else {
126
156
#pragma clang diagnostic push
127
157
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
128
- [RCTSharedApplication () setStatusBarHidden: hidden
129
- withAnimation: animation];
158
+ [RCTSharedApplication () setStatusBarHidden: hidden withAnimation: animation];
130
159
#pragma clang diagnostic pop
131
160
}
132
161
}
133
162
134
- RCT_EXPORT_METHOD (setNetworkActivityIndicatorVisible: (BOOL )visible)
163
+ RCT_EXPORT_METHOD (setNetworkActivityIndicatorVisible : (BOOL )visible)
135
164
{
136
165
RCTSharedApplication ().networkActivityIndicatorVisible = visible;
137
166
}
138
167
139
- #endif // TARGET_OS_TV
168
+ #endif // TARGET_OS_TV
140
169
141
170
@end
0 commit comments