diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm index 054aa5ca8d3..887aed735dc 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm @@ -39,16 +39,11 @@ RCT_EXPORT_MODULE() - (NSDictionary *)getConstants { - __block NSDictionary *constants; - RCTUnsafeExecuteOnMainQueueSync(^{ - constants = @{ - @"const1" : @YES, - @"const2" : @(390), - @"const3" : @"something", - }; - }); - - return constants; + return @{ + @"const1" : @YES, + @"const2" : @(390), + @"const3" : @"something", + }; } // TODO: Remove once fully migrated to TurboModule. diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm index 4813d906a5e..e19ec0485a5 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm @@ -9,16 +9,19 @@ #import "RCTSampleTurboModulePlugin.h" #import +#import #import #import #import using namespace facebook::react; -@interface RCTSampleTurboModule () +@interface RCTSampleTurboModule () @end -@implementation RCTSampleTurboModule +@implementation RCTSampleTurboModule { + NSDictionary *_constants; +} // Backward-compatible export RCT_EXPORT_MODULE() @@ -29,6 +32,18 @@ RCT_EXPORT_MODULE() return YES; } +- (void)initialize +{ + UIScreen *mainScreen = UIScreen.mainScreen; + CGSize screenSize = mainScreen.bounds.size; + + _constants = @{ + @"const1" : @YES, + @"const2" : @(screenSize.width), + @"const3" : @"something", + }; +} + - (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); @@ -49,19 +64,7 @@ RCT_EXPORT_MODULE() - (NSDictionary *)getConstants { - __block NSDictionary *constants; - RCTUnsafeExecuteOnMainQueueSync(^{ - UIScreen *mainScreen = UIScreen.mainScreen; - CGSize screenSize = mainScreen.bounds.size; - - constants = @{ - @"const1" : @YES, - @"const2" : @(screenSize.width), - @"const3" : @"something", - }; - }); - - return constants; + return _constants; } // TODO: Remove once fully migrated to TurboModule. diff --git a/packages/rn-tester/package.json b/packages/rn-tester/package.json index 91b371db388..4cd6c089141 100644 --- a/packages/rn-tester/package.json +++ b/packages/rn-tester/package.json @@ -44,8 +44,15 @@ "javaPackageName": "com.facebook.fbreact.specs" }, "ios": { - "componentProvider": { - "RNTMyNativeView": "RNTMyNativeViewComponentView" + "modules": { + "SampleTurboModule": { + "unstableRequiresMainQueueSetup": true + } + }, + "components": { + "RNTMyNativeView": { + "className": "RNTMyNativeViewComponentView" + } } } },