remove requirement for main queue setup for RCTPlatform (#49474)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49474

changelog: [internal]

Can move setup to the background setup:
1. Use RCTTraitCollectionProxy to access current trait collection to check if force touch is available.
2. UIDevice.currentDevice is thread safe and can be read safely from a background thread.

Reviewed By: rshest

Differential Revision: D69744257

fbshipit-source-id: 8857a827c3d3e03a9b2ced15e6970d728693a043
This commit is contained in:
Samuel Susla
2025-02-19 05:37:54 -08:00
committed by Facebook GitHub Bot
parent 29114dd914
commit 0e540298ae
@@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTTraitCollectionProxy.h>
#import <React/RCTUtils.h>
#import <React/RCTVersion.h>
@@ -48,7 +49,7 @@ RCT_EXPORT_MODULE(PlatformConstants)
+ (BOOL)requiresMainQueueSetup
{
return YES;
return NO;
}
- (dispatch_queue_t)methodQueue
@@ -64,30 +65,27 @@ RCT_EXPORT_MODULE(PlatformConstants)
- (ModuleConstants<JS::NativePlatformConstantsIOS::Constants>)getConstants
{
__block ModuleConstants<JS::NativePlatformConstantsIOS::Constants> constants;
RCTUnsafeExecuteOnMainQueueSync(^{
UIDevice *device = [UIDevice currentDevice];
auto versions = RCTGetReactNativeVersion();
constants = typedConstants<JS::NativePlatformConstantsIOS::Constants>({
.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]] ? nullptr : versions[@"prerelease"]}),
UIDevice *device = [UIDevice currentDevice];
bool isForceTouchAvailable = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection.forceTouchCapability ==
UIForceTouchCapabilityAvailable;
auto versions = RCTGetReactNativeVersion();
return typedConstants<JS::NativePlatformConstantsIOS::Constants>({
.forceTouchAvailable = isForceTouchAvailable,
.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]] ? nullptr : versions[@"prerelease"]}),
#if TARGET_OS_MACCATALYST
.isMacCatalyst = true,
.isMacCatalyst = true,
#else
.isMacCatalyst = false,
.isMacCatalyst = false,
#endif
});
});
return constants;
}
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params