diff --git a/React-Core.podspec b/React-Core.podspec index e7ea6db16160d1..8954b949c12a92 100644 --- a/React-Core.podspec +++ b/React-Core.podspec @@ -47,7 +47,7 @@ Pod::Spec.new do |s| s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags s.header_dir = "React" s.framework = "JavaScriptCore" - s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/RCT-Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\" \"${PODS_ROOT}/Headers/Public/FlipperKit\"", "DEFINES_MODULE" => "YES" } + s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/RCT-Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\" \"${PODS_ROOT}/Headers/Public/FlipperKit\" \"$(PODS_ROOT)/Headers/Public/ReactCommon\"", "DEFINES_MODULE" => "YES" } s.user_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Headers/Private/React-Core\""} s.default_subspec = "Default" diff --git a/React/AppSetup/RCTAppSetupUtils.h b/React/AppSetup/RCTAppSetupUtils.h index 8f6865e4f4fcce..c4e30d86265334 100644 --- a/React/AppSetup/RCTAppSetupUtils.h +++ b/React/AppSetup/RCTAppSetupUtils.h @@ -9,9 +9,35 @@ #import #import +#if RCT_TM_FABRIC_ENABLED + +#ifndef RCT_USE_HERMES +#if __has_include() +#define RCT_USE_HERMES 1 +#else +#define RCT_USE_HERMES 0 +#endif +#endif + +#if RCT_USE_HERMES +#import +#else +#import +#endif + +#import +#endif + @interface RCTAppSetupUtils : NSObject + (void)prepareApp:(UIApplication *_Nonnull)application; + (RCTRootView *_Nonnull)defaultRootViewWithBridge:(RCTBridge *_Nonnull)bridge moduleName:(NSString *_Nonnull)moduleName initialProperties:(nullable NSDictionary *)initialProperties; + +#if RCT_TM_FABRIC_ENABLED ++ (id _Nonnull)defaultModuleInstanceFromClass:(Class _Nonnull)moduleClass; ++ (std::unique_ptr) + defaultJsExecutorFactoryForBridge:(RCTBridge *_Nonnull)bridge + withTurboModuleManager:(RCTTurboModuleManager *_Nonnull)turboModuleManager; +#endif @end diff --git a/React/AppSetup/RCTAppSetupUtils.mm b/React/AppSetup/RCTAppSetupUtils.mm index 85edbc131f82a0..9ecfb47b796573 100644 --- a/React/AppSetup/RCTAppSetupUtils.mm +++ b/React/AppSetup/RCTAppSetupUtils.mm @@ -7,6 +7,18 @@ #import "RCTAppSetupUtils.h" +#if RCT_TM_FABRIC_ENABLED +#import +#import +#import +#import +#import +#import +#import +#import +#import +#endif + #ifdef FB_SONARKIT_ENABLED #import #import @@ -35,6 +47,10 @@ + (void)prepareApp:(UIApplication *)application #ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif + +#if RCT_TM_FABRIC_ENABLED + RCTEnableTurboModule(YES); +#endif } + (RCTRootView *)defaultRootViewWithBridge:(RCTBridge *)bridge @@ -44,4 +60,66 @@ + (RCTRootView *)defaultRootViewWithBridge:(RCTBridge *)bridge return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; } +#if RCT_TM_FABRIC_ENABLED ++ (id)defaultModuleInstanceFromClass:(Class)moduleClass +{ + // Set up the default RCTImageLoader and RCTNetworking modules. + if (moduleClass == RCTImageLoader.class) { + return [[moduleClass alloc] initWithRedirectDelegate:nil + loadersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { + return @[ [RCTLocalAssetImageLoader new] ]; + } + decodersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { + return @[ [RCTGIFImageDecoder new] ]; + }]; + } else if (moduleClass == RCTNetworking.class) { + return [[moduleClass alloc] + initWithHandlersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { + return @[ + [RCTHTTPRequestHandler new], + [RCTDataRequestHandler new], + [RCTFileRequestHandler new], + ]; + }]; + } + // No custom initializer here. + return [moduleClass new]; +} + ++ (std::unique_ptr)defaultJsExecutorFactoryForBridge:(RCTBridge *)bridge + withTurboModuleManager: + (RCTTurboModuleManager *)turboModuleManager; +{ + // Necessary to allow NativeModules to lookup TurboModules + [bridge setRCTTurboModuleRegistry:turboModuleManager]; + +#if RCT_DEV + if (!RCTTurboModuleEagerInitEnabled()) { + /** + * Instantiating DevMenu has the side-effect of registering + * shortcuts for CMD + d, CMD + i, and CMD + n via RCTDevMenu. + * Therefore, when TurboModules are enabled, we must manually create this + * NativeModule. + */ + [turboModuleManager moduleForName:"RCTDevMenu"]; + } +#endif + +#if RCT_USE_HERMES + return std::make_unique( +#else + return std::make_unique( +#endif + facebook::react::RCTJSIExecutorRuntimeInstaller([turboModuleManager, bridge](facebook::jsi::Runtime &runtime) { + if (!bridge || !turboModuleManager) { + return; + } + facebook::react::RuntimeExecutor syncRuntimeExecutor = + [&](std::function &&callback) { callback(runtime); }; + [turboModuleManager installJSBindingWithRuntimeExecutor:syncRuntimeExecutor]; + })); +} + +#endif + @end diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 3a892b62d8c87b..48e63ed7700ac9 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -901,7 +901,7 @@ SPEC CHECKSUMS: React: f64c9f6db5428717922a3292ba6a448615a2e143 React-callinvoker: c5d61e29df57793f0dc10ec2bc01c846f863e51f React-Codegen: 2256e335ccce7326eeca6d7a668e05c4de259289 - React-Core: 50d95abfb3c60d95e33a4b74e05e2a414bea4b73 + React-Core: 2753750098f0ad7e351a61c2e63d44ae0e95c3fe React-CoreModules: a8e2bdc1ebbf8d440478456197abd58d1691f61a React-cxxreact: cfc1663dae1ea52b465bbf021ef7b1527c5dc80c React-Fabric: 002345cff43721617e0a3c0866f6f76bae8c50ff diff --git a/template/ios/HelloWorld.xcodeproj/project.pbxproj b/template/ios/HelloWorld.xcodeproj/project.pbxproj index 29d5c42c340e7e..b383416d524bf0 100644 --- a/template/ios/HelloWorld.xcodeproj/project.pbxproj +++ b/template/ios/HelloWorld.xcodeproj/project.pbxproj @@ -482,6 +482,7 @@ baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-HelloWorld.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_BITCODE = NO; @@ -508,6 +509,7 @@ baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-HelloWorld.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; INFOPLIST_FILE = HelloWorld/Info.plist; @@ -588,6 +590,12 @@ ); MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + ); SDKROOT = iphoneos; }; name = Debug; @@ -645,6 +653,12 @@ "\"$(inherited)\"", ); MTL_ENABLE_DEBUG_INFO = NO; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + ); SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; diff --git a/template/ios/HelloWorld/AppDelegate.mm b/template/ios/HelloWorld/AppDelegate.mm index 77f92aa529bffa..492306608b662d 100644 --- a/template/ios/HelloWorld/AppDelegate.mm +++ b/template/ios/HelloWorld/AppDelegate.mm @@ -6,6 +6,17 @@ #import +#if RCT_TM_FABRIC_ENABLED +#import +#import +#import + +@interface AppDelegate () { + RCTTurboModuleManager *_turboModuleManager; +} +@end +#endif + @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -40,4 +51,42 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge #endif } +#if RCT_TM_FABRIC_ENABLED + +#pragma mark - RCTCxxBridgeDelegate + +- (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge +{ + _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge + delegate:self + jsInvoker:bridge.jsCallInvoker]; + return [RCTAppSetupUtils defaultJsExecutorFactoryForBridge:bridge withTurboModuleManager:_turboModuleManager]; +} + +#pragma mark RCTTurboModuleManagerDelegate + +- (Class)getModuleClassFromName:(const char *)name +{ + return RCTCoreModulesClassProvider(name); +} + +- (std::shared_ptr)getTurboModule:(const std::string &)name + jsInvoker:(std::shared_ptr)jsInvoker +{ + return nullptr; +} + +- (std::shared_ptr)getTurboModule:(const std::string &)name + initParams:(const facebook::react::ObjCTurboModule::InitParams &)params +{ + return nullptr; +} + +- (id)getModuleInstanceFromClass:(Class)moduleClass +{ + return [RCTAppSetupUtils defaultModuleInstanceFromClass: moduleClass]; +} + +#endif + @end