diff --git a/React/CoreModules/RCTAppState.mm b/React/CoreModules/RCTAppState.mm index 4211d760d103e8..66a1e72693f2f6 100644 --- a/React/CoreModules/RCTAppState.mm +++ b/React/CoreModules/RCTAppState.mm @@ -56,9 +56,14 @@ - (dispatch_queue_t)methodQueue - (facebook::react::ModuleConstants)getConstants { - return facebook::react::typedConstants({ - .initialAppState = RCTCurrentAppState(), + __block facebook::react::ModuleConstants constants; + RCTUnsafeExecuteOnMainQueueSync(^{ + constants = facebook::react::typedConstants({ + .initialAppState = RCTCurrentAppState(), + }); }); + + return constants; } #pragma mark - Lifecycle diff --git a/React/CoreModules/RCTDeviceInfo.mm b/React/CoreModules/RCTDeviceInfo.mm index 7a168b510ce600..eb5f8217946238 100644 --- a/React/CoreModules/RCTDeviceInfo.mm +++ b/React/CoreModules/RCTDeviceInfo.mm @@ -122,14 +122,19 @@ static BOOL RCTIsIPhoneX() - (NSDictionary *)getConstants { - return @{ - @"Dimensions" : RCTExportedDimensions(_bridge), - // Note: - // This prop is deprecated and will be removed in a future release. - // Please use this only for a quick and temporary solution. - // Use instead. - @"isIPhoneX_deprecated" : @(RCTIsIPhoneX()), - }; + __block NSDictionary *constants; + RCTUnsafeExecuteOnMainQueueSync(^{ + constants = @{ + @"Dimensions" : RCTExportedDimensions(self->_bridge), + // Note: + // This prop is deprecated and will be removed in a future release. + // Please use this only for a quick and temporary solution. + // Use instead. + @"isIPhoneX_deprecated" : @(RCTIsIPhoneX()), + }; + }); + + return constants; } - (void)didReceiveNewContentSizeMultiplier diff --git a/React/CoreModules/RCTPlatform.mm b/React/CoreModules/RCTPlatform.mm index 3f637d48e66055..fdf746726215db 100644 --- a/React/CoreModules/RCTPlatform.mm +++ b/React/CoreModules/RCTPlatform.mm @@ -58,22 +58,27 @@ - (dispatch_queue_t)methodQueue - (ModuleConstants)getConstants { - UIDevice *device = [UIDevice currentDevice]; - auto versions = RCTGetReactNativeVersion(); - return typedConstants({ - .forceTouchAvailable = RCTForceTouchAvailable() ? true : false, - .osVersion = [device systemVersion], - .systemName = [device systemName], - .interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]), - .isTesting = RCTRunningInTestEnvironment() ? true : false, - .reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder( - {.minor = [versions[@"minor"] doubleValue], - .major = [versions[@"major"] doubleValue], - .patch = [versions[@"patch"] doubleValue], - .prerelease = [versions[@"prerelease"] isKindOfClass:[NSNull class]] - ? folly::Optional{} - : [versions[@"prerelease"] doubleValue]}), + __block ModuleConstants constants; + RCTUnsafeExecuteOnMainQueueSync(^{ + UIDevice *device = [UIDevice currentDevice]; + auto versions = RCTGetReactNativeVersion(); + constants = typedConstants({ + .forceTouchAvailable = RCTForceTouchAvailable() ? true : false, + .osVersion = [device systemVersion], + .systemName = [device systemName], + .interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]), + .isTesting = RCTRunningInTestEnvironment() ? true : false, + .reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder( + {.minor = [versions[@"minor"] doubleValue], + .major = [versions[@"major"] doubleValue], + .patch = [versions[@"patch"] doubleValue], + .prerelease = [versions[@"prerelease"] isKindOfClass:[NSNull class]] + ? folly::Optional{} + : [versions[@"prerelease"] doubleValue]}), + }); }); + + return constants; } - (std::shared_ptr)getTurboModule:(const ObjCTurboModule::InitParams &)params diff --git a/React/CoreModules/RCTStatusBarManager.mm b/React/CoreModules/RCTStatusBarManager.mm index 3dd462a8b78dde..3e62b9df5052c7 100644 --- a/React/CoreModules/RCTStatusBarManager.mm +++ b/React/CoreModules/RCTStatusBarManager.mm @@ -185,10 +185,15 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification - (facebook::react::ModuleConstants)getConstants { - return facebook::react::typedConstants({ - .HEIGHT = RCTSharedApplication().statusBarFrame.size.height, - .DEFAULT_BACKGROUND_COLOR = folly::none, + __block facebook::react::ModuleConstants constants; + RCTUnsafeExecuteOnMainQueueSync(^{ + constants = facebook::react::typedConstants({ + .HEIGHT = RCTSharedApplication().statusBarFrame.size.height, + .DEFAULT_BACKGROUND_COLOR = folly::none, + }); }); + + return constants; } - (facebook::react::ModuleConstants)constantsToExport diff --git a/ReactCommon/turbomodule/samples/platform/ios/RCTSampleTurboModule.mm b/ReactCommon/turbomodule/samples/platform/ios/RCTSampleTurboModule.mm index a875ff521ad998..7fa051eae33807 100644 --- a/ReactCommon/turbomodule/samples/platform/ios/RCTSampleTurboModule.mm +++ b/ReactCommon/turbomodule/samples/platform/ios/RCTSampleTurboModule.mm @@ -7,6 +7,7 @@ #import "RCTSampleTurboModule.h" +#import #import using namespace facebook::react; @@ -45,14 +46,19 @@ - (void)invalidate - (NSDictionary *)getConstants { - UIScreen *mainScreen = UIScreen.mainScreen; - CGSize screenSize = mainScreen.bounds.size; + __block NSDictionary *constants; + RCTUnsafeExecuteOnMainQueueSync(^{ + UIScreen *mainScreen = UIScreen.mainScreen; + CGSize screenSize = mainScreen.bounds.size; - return @{ - @"const1" : @YES, - @"const2" : @(screenSize.width), - @"const3" : @"something", - }; + constants = @{ + @"const1" : @YES, + @"const2" : @(screenSize.width), + @"const3" : @"something", + }; + }); + + return constants; } // TODO: Remove once fully migrated to TurboModule.