Skip to content

Commit

Permalink
dispatch status bar methods onto main queue (facebook#39759)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#39759

Changelog: [Internal]

as part of the sync void tm methods test, there are some modules that do not behave correctly when trying to execute their methods on the js thread.

this module accesses UIKit, so we explicitly dispatch async to the main thread

Reviewed By: mdvacca

Differential Revision: D49835587

fbshipit-source-id: 5527fa6a3e2cbe3769daead0fa6be3a904bf6543
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 4, 2023
1 parent 925acc4 commit b972e9e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/react-native/React/CoreModules/RCTStatusBarManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ - (void)stopObserving
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

- (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notification
{
CGRect frame = [notification.userInfo[UIApplicationStatusBarFrameUserInfoKey] CGRectValue];
Expand Down Expand Up @@ -130,35 +125,41 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification

RCT_EXPORT_METHOD(setStyle : (NSString *)style animated : (BOOL)animated)
{
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
dispatch_async(dispatch_get_main_queue(), ^{
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
} else {
} 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 : (NSString *)withAnimation)
{
UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation];
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
dispatch_async(dispatch_get_main_queue(), ^{
UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation];
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
} else {
} 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)
{
RCTSharedApplication().networkActivityIndicatorVisible = visible;
dispatch_async(dispatch_get_main_queue(), ^{
RCTSharedApplication().networkActivityIndicatorVisible = visible;
});
}

- (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)getConstants
Expand Down

0 comments on commit b972e9e

Please sign in to comment.