From ad2b5926319f9946a32a48da16c57ab6fee51ed5 Mon Sep 17 00:00:00 2001 From: gaodeng Date: Mon, 2 Sep 2019 09:20:58 +0800 Subject: [PATCH 1/3] iOS13 status bar has now 3 styles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iOS13 status bar has now 3 styles UIStatusBarStyleDefault, UIStatusBarStyleLightContent, UIStatusBarStyleDarkContent UIStatusBarStyleDefault now acts as an automatic style which will set it’s value dynamically based on the the userinterfacestyle(One of the traits) of the viewcontroller that controls the status bar appearance. --- React/Modules/RCTStatusBarManager.m | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/React/Modules/RCTStatusBarManager.m b/React/Modules/RCTStatusBarManager.m index 9b6f9d6698c156..d3891219b0d6b6 100644 --- a/React/Modules/RCTStatusBarManager.m +++ b/React/Modules/RCTStatusBarManager.m @@ -14,12 +14,25 @@ #if !TARGET_OS_TV @implementation RCTConvert (UIStatusBar) +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ +__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 + RCT_ENUM_CONVERTER(UIStatusBarStyle, (@{ - @"default": @(UIStatusBarStyleDefault), - @"light-content": @(UIStatusBarStyleLightContent), - @"dark-content": @(UIStatusBarStyleDefault), + @"default": @(UIStatusBarStyleDefault), + @"light-content": @(UIStatusBarStyleLightContent), + @"dark-content": @available(iOS 13.0, *) ? @(UIStatusBarStyleDarkContent):@(UIStatusBarStyleDefault) }), UIStatusBarStyleDefault, integerValue); +#else + +RCT_ENUM_CONVERTER(UIStatusBarStyle, (@{ + @"default": @(UIStatusBarStyleDefault), + @"light-content": @(UIStatusBarStyleLightContent), + @"dark-content": @(UIStatusBarStyleDefault) + }), UIStatusBarStyleDefault, integerValue); + +#endif + RCT_ENUM_CONVERTER(UIStatusBarAnimation, (@{ @"none": @(UIStatusBarAnimationNone), @"fade": @(UIStatusBarAnimationFade), From b87fc9f6d28ebd43aa56117116dd843b1937089d Mon Sep 17 00:00:00 2001 From: gaodeng Date: Tue, 3 Sep 2019 22:23:05 +0800 Subject: [PATCH 2/3] fix @available does not guard availability here; use if (@available) instead --- React/Modules/RCTStatusBarManager.m | 40 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/React/Modules/RCTStatusBarManager.m b/React/Modules/RCTStatusBarManager.m index d3891219b0d6b6..7c066d60b1b37f 100644 --- a/React/Modules/RCTStatusBarManager.m +++ b/React/Modules/RCTStatusBarManager.m @@ -14,24 +14,34 @@ #if !TARGET_OS_TV @implementation RCTConvert (UIStatusBar) ++ (UIStatusBarStyle)UIStatusBarStyle:(id)json RCT_DYNAMIC +{ + static NSDictionary *mapping; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + if(@available(iOS 13.0, *)){ + mapping=@{ + @"default": @(UIStatusBarStyleDefault), + @"light-content": @(UIStatusBarStyleLightContent), #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ -__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 - -RCT_ENUM_CONVERTER(UIStatusBarStyle, (@{ - @"default": @(UIStatusBarStyleDefault), - @"light-content": @(UIStatusBarStyleLightContent), - @"dark-content": @available(iOS 13.0, *) ? @(UIStatusBarStyleDarkContent):@(UIStatusBarStyleDefault) -}), UIStatusBarStyleDefault, integerValue); - + __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 + @"dark-content": @(UIStatusBarStyleDarkContent) #else - -RCT_ENUM_CONVERTER(UIStatusBarStyle, (@{ - @"default": @(UIStatusBarStyleDefault), - @"light-content": @(UIStatusBarStyleLightContent), - @"dark-content": @(UIStatusBarStyleDefault) - }), UIStatusBarStyleDefault, integerValue); - + @"dark-content": @(UIStatusBarStyleDefault) #endif + }; + + }else{ + mapping=@{ + @"default": @(UIStatusBarStyleDefault), + @"light-content": @(UIStatusBarStyleLightContent), + @"dark-content": @(UIStatusBarStyleDefault) + }; + } + + }); + return _RCT_CAST(type, [RCTConvertEnumValue("UIStatusBarStyle", mapping, @(UIStatusBarStyleDefault), json) integerValue]); +} RCT_ENUM_CONVERTER(UIStatusBarAnimation, (@{ @"none": @(UIStatusBarAnimationNone), From 3586215b23132658a734e6767b411bc1beb13179 Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Wed, 11 Sep 2019 11:51:32 +0100 Subject: [PATCH 3/3] Reformat --- React/Modules/RCTStatusBarManager.m | 100 +++++++++++++++------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/React/Modules/RCTStatusBarManager.m b/React/Modules/RCTStatusBarManager.m index 7c066d60b1b37f..d15fd73cce93ce 100644 --- a/React/Modules/RCTStatusBarManager.m +++ b/React/Modules/RCTStatusBarManager.m @@ -19,35 +19,39 @@ + (UIStatusBarStyle)UIStatusBarStyle:(id)json RCT_DYNAMIC static NSDictionary *mapping; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - if(@available(iOS 13.0, *)){ - mapping=@{ - @"default": @(UIStatusBarStyleDefault), - @"light-content": @(UIStatusBarStyleLightContent), + if (@available(iOS 13.0, *)) { + mapping = @{ + @"default" : @(UIStatusBarStyleDefault), + @"light-content" : @(UIStatusBarStyleLightContent), #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ - __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 - @"dark-content": @(UIStatusBarStyleDarkContent) + __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 + @"dark-content" : @(UIStatusBarStyleDarkContent) #else @"dark-content": @(UIStatusBarStyleDefault) #endif - }; - - }else{ - mapping=@{ - @"default": @(UIStatusBarStyleDefault), - @"light-content": @(UIStatusBarStyleLightContent), - @"dark-content": @(UIStatusBarStyleDefault) - }; - } - + }; + + } else { + mapping = @{ + @"default" : @(UIStatusBarStyleDefault), + @"light-content" : @(UIStatusBarStyleLightContent), + @"dark-content" : @(UIStatusBarStyleDefault) + }; + } }); - return _RCT_CAST(type, [RCTConvertEnumValue("UIStatusBarStyle", mapping, @(UIStatusBarStyleDefault), json) integerValue]); + return _RCT_CAST( + type, [RCTConvertEnumValue("UIStatusBarStyle", mapping, @(UIStatusBarStyleDefault), json) integerValue]); } -RCT_ENUM_CONVERTER(UIStatusBarAnimation, (@{ - @"none": @(UIStatusBarAnimationNone), - @"fade": @(UIStatusBarAnimationFade), - @"slide": @(UIStatusBarAnimationSlide), -}), UIStatusBarAnimationNone, integerValue); +RCT_ENUM_CONVERTER( + UIStatusBarAnimation, + (@{ + @"none" : @(UIStatusBarAnimationNone), + @"fade" : @(UIStatusBarAnimationFade), + @"slide" : @(UIStatusBarAnimationSlide), + }), + UIStatusBarAnimationNone, + integerValue); @end #endif @@ -59,8 +63,9 @@ static BOOL RCTViewControllerBasedStatusBarAppearance() static BOOL value; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - value = [[[NSBundle mainBundle] objectForInfoDictionaryKey: - @"UIViewControllerBasedStatusBarAppearance"] ?: @YES boolValue]; + value = + [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] + ?: @YES boolValue]; }); return value; @@ -70,8 +75,7 @@ static BOOL RCTViewControllerBasedStatusBarAppearance() - (NSArray *)supportedEvents { - return @[@"statusBarFrameDidChange", - @"statusBarFrameWillChange"]; + return @[ @"statusBarFrameDidChange", @"statusBarFrameWillChange" ]; } #if !TARGET_OS_TV @@ -79,8 +83,14 @@ static BOOL RCTViewControllerBasedStatusBarAppearance() - (void)startObserving { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(applicationDidChangeStatusBarFrame:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil]; - [nc addObserver:self selector:@selector(applicationWillChangeStatusBarFrame:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil]; + [nc addObserver:self + selector:@selector(applicationDidChangeStatusBarFrame:) + name:UIApplicationDidChangeStatusBarFrameNotification + object:nil]; + [nc addObserver:self + selector:@selector(applicationWillChangeStatusBarFrame:) + name:UIApplicationWillChangeStatusBarFrameNotification + object:nil]; } - (void)stopObserving @@ -97,11 +107,11 @@ - (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notifi { CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue]; NSDictionary *event = @{ - @"frame": @{ - @"x": @(frame.origin.x), - @"y": @(frame.origin.y), - @"width": @(frame.size.width), - @"height": @(frame.size.height), + @"frame" : @{ + @"x" : @(frame.origin.x), + @"y" : @(frame.origin.y), + @"width" : @(frame.size.width), + @"height" : @(frame.size.height), }, }; [self sendEventWithName:eventName body:event]; @@ -117,15 +127,14 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification [self emitEvent:@"statusBarFrameWillChange" forNotification:notification]; } -RCT_EXPORT_METHOD(getHeight:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getHeight : (RCTResponseSenderBlock)callback) { - callback(@[@{ - @"height": @(RCTSharedApplication().statusBarFrame.size.height), - }]); + callback(@[ @{ + @"height" : @(RCTSharedApplication().statusBarFrame.size.height), + } ]); } -RCT_EXPORT_METHOD(setStyle:(UIStatusBarStyle)statusBarStyle - animated:(BOOL)animated) +RCT_EXPORT_METHOD(setStyle : (UIStatusBarStyle)statusBarStyle animated : (BOOL)animated) { if (RCTViewControllerBasedStatusBarAppearance()) { RCTLogError(@"RCTStatusBarManager module requires that the \ @@ -133,14 +142,12 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [RCTSharedApplication() setStatusBarStyle:statusBarStyle - animated:animated]; + [RCTSharedApplication() setStatusBarStyle:statusBarStyle animated:animated]; } #pragma clang diagnostic pop } -RCT_EXPORT_METHOD(setHidden:(BOOL)hidden - withAnimation:(UIStatusBarAnimation)animation) +RCT_EXPORT_METHOD(setHidden : (BOOL)hidden withAnimation : (UIStatusBarAnimation)animation) { if (RCTViewControllerBasedStatusBarAppearance()) { RCTLogError(@"RCTStatusBarManager module requires that the \ @@ -148,17 +155,16 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification } else { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [RCTSharedApplication() setStatusBarHidden:hidden - withAnimation:animation]; + [RCTSharedApplication() setStatusBarHidden:hidden withAnimation:animation]; #pragma clang diagnostic pop } } -RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible:(BOOL)visible) +RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible : (BOOL)visible) { RCTSharedApplication().networkActivityIndicatorVisible = visible; } -#endif //TARGET_OS_TV +#endif // TARGET_OS_TV @end