diff --git a/packages/react-native/Libraries/AppDelegate/RCTLegacyInteropComponents.mm b/packages/react-native/Libraries/AppDelegate/RCTLegacyInteropComponents.mm index d1d68376b08493..549e41a9b91b5f 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTLegacyInteropComponents.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTLegacyInteropComponents.mm @@ -1,3 +1,4 @@ + /* * Copyright (c) Meta Platforms, Inc. and affiliates. * @@ -11,7 +12,7 @@ @implementation RCTLegacyInteropComponents + (NSArray *)legacyInteropComponents { - return @[]; + return @[ @"RNTMyLegacyNativeView" ]; } @end diff --git a/packages/rn-tester/RNTester/AppDelegate.h b/packages/rn-tester/RNTester/AppDelegate.h index 55625d8693c2a8..d172167ee1d627 100644 --- a/packages/rn-tester/RNTester/AppDelegate.h +++ b/packages/rn-tester/RNTester/AppDelegate.h @@ -5,13 +5,9 @@ * LICENSE file in the root directory of this source tree. */ +#import #import -@class RCTBridge; - -@interface AppDelegate : UIResponder - -@property (nonatomic, strong) UIWindow *window; -@property (nonatomic, readonly) RCTBridge *bridge; +@interface AppDelegate : RCTAppDelegate @end diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index bb1cbe68f73ee8..9b92dbc99b5bd9 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -7,152 +7,42 @@ #import "AppDelegate.h" -#ifndef RCT_USE_HERMES -#if __has_include() -#define RCT_USE_HERMES 1 -#else -#define RCT_USE_HERMES 0 -#endif -#endif - -#ifdef RCT_NEW_ARCH_ENABLED -#ifndef RN_FABRIC_ENABLED -#define RN_FABRIC_ENABLED -#endif -#endif - -#if RCT_USE_HERMES -#import -#else -#import -#endif - -#import #import -#import -#import -#import -#import -#import -#import -#import -#import #import -#import -#import -#import - -#import +#import "RNTesterTurboModuleProvider.h" #if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC #import #endif -#ifdef RN_FABRIC_ENABLED -#import -#import -#import -#import - -#import -#import -#import -#import -#import -#endif - -#if RCT_NEW_ARCH_ENABLED -#import -#endif - -#if DEBUG -#ifdef FB_SONARKIT_ENABLED -#import -#import -#import -#import -#import -#import -#import -#endif -#endif +// RCTImage +#import +#import +#import +#import -#import -#import "RNTesterTurboModuleProvider.h" +// RCTNetworking +#import -@interface AppDelegate () { -#ifdef RN_FABRIC_ENABLED - RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; - std::shared_ptr _reactNativeConfig; - facebook::react::ContextContainer::Shared _contextContainer; - std::shared_ptr _runtimeScheduler; -#endif -} -@end +// RCTURLRequestHandlers +#import +#import +#import #if RCT_NEW_ARCH_ENABLED -/// Declare conformance to `RCTComponentViewFactoryComponentProvider` -@interface AppDelegate () -@end +#import #endif -static NSString *const kRNConcurrentRoot = @"concurrentRoot"; - @implementation AppDelegate -#ifdef RN_FABRIC_ENABLED -- (instancetype)init +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - if (self = [super init]) { - _contextContainer = std::make_shared(); - _reactNativeConfig = std::make_shared(); - _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); - } - return self; -} -#endif - -- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - RCTEnableTurboModule(YES); - - _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; + self.moduleName = @"RNTesterApp"; + // You can add your custom initial props in the dictionary below. + // They will be passed down to the ViewController used by React Native. + self.initialProps = [self prepareInitialProps]; - // Appetizer.io params check - NSDictionary *initProps = [self prepareInitialProps]; - -#if RCT_NEW_ARCH_ENABLED - [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; -#endif - -#ifdef RN_FABRIC_ENABLED - _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:_bridge contextContainer:_contextContainer]; - - _bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; - - UIView *rootView = [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:_bridge - moduleName:@"RNTesterApp" - initialProperties:initProps]; - - [self registerPaperComponents:@[ @"RNTMyLegacyNativeView" ]]; -#else - UIView *rootView = [[RCTRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps]; -#endif - - self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - UIViewController *rootViewController = [UIViewController new]; - rootViewController.view = rootView; - self.window.rootViewController = rootViewController; - [self.window makeKeyAndVisible]; - [self initializeFlipper:application]; - - return YES; -} - -- (BOOL)concurrentRootEnabled -{ - // Switch this bool to turn on and off the concurrent root - return true; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } - (NSDictionary *)prepareInitialProps @@ -164,33 +54,14 @@ - (NSDictionary *)prepareInitialProps initProps[@"exampleFromAppetizeParams"] = [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]; } -#ifdef RN_FABRIC_ENABLED - initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); -#endif - return initProps; } -- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"js/RNTesterApp.ios"]; } - -- (void)initializeFlipper:(UIApplication *)application -{ -#if DEBUG -#ifdef FB_SONARKIT_ENABLED - FlipperClient *client = [FlipperClient sharedClient]; - SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; - [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application - withDescriptorMapper:layoutDescriptorMapper]]; - [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; - [client addPlugin:[FlipperKitReactPlugin new]]; - [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; - [client start]; -#endif -#endif -} +//[self registerPaperComponents:@[ @"RNTMyLegacyNativeView" ]]; - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url @@ -206,62 +77,6 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge [RCTJavaScriptLoader loadBundleAtURL:[self sourceURLForBridge:bridge] onProgress:onProgress onComplete:loadCallback]; } -#pragma mark - RCTCxxBridgeDelegate - -// This function is called during -// `[[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];` -- (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge -{ - std::shared_ptr callInvoker = bridge.jsCallInvoker; - -#ifdef RN_FABRIC_ENABLED - _runtimeScheduler = std::make_shared(RCTRuntimeExecutorFromBridge(bridge)); - _contextContainer->erase("RuntimeScheduler"); - _contextContainer->insert("RuntimeScheduler", _runtimeScheduler); - callInvoker = std::make_shared(_runtimeScheduler); -#endif - - RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge - delegate:self - jsInvoker:callInvoker]; - [bridge setRCTTurboModuleRegistry:turboModuleManager]; - -#if RCT_DEV - /** - * Eagerly initialize RCTDevMenu so CMD + d, CMD + i, and CMD + r work. - * This is a stop gap until we have a system to eagerly init Turbo Modules. - */ - [turboModuleManager moduleForName:"RCTDevMenu"]; -#endif - - __weak __typeof(self) weakSelf = self; - -#if RCT_USE_HERMES - return std::make_unique( -#else - return std::make_unique( -#endif - facebook::react::RCTJSIExecutorRuntimeInstaller([weakSelf, bridge, turboModuleManager]( - facebook::jsi::Runtime &runtime) { - if (!bridge) { - return; - } - -#if RN_FABRIC_ENABLED - __typeof(self) strongSelf = weakSelf; - if (strongSelf && strongSelf->_runtimeScheduler) { - facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, strongSelf->_runtimeScheduler); - } -#endif - - facebook::react::RuntimeExecutor syncRuntimeExecutor = - [&](std::function &&callback) { callback(runtime); }; - [turboModuleManager installJSBindingWithRuntimeExecutor:syncRuntimeExecutor]; - })); -} - -#pragma mark - RCTTurboModuleManagerDelegate - - (Class)getModuleClassFromName:(const char *)name { return facebook::react::RNTesterTurboModuleClassProvider(name); @@ -297,19 +112,6 @@ - (Class)getModuleClassFromName:(const char *)name return [moduleClass new]; } -#pragma mark - Interop layer - -- (void)registerPaperComponents:(NSArray *)components -{ -#if RCT_NEW_ARCH_ENABLED - for (NSString *component in components) { - [RCTLegacyViewManagerInteropComponentView supportLegacyViewManagerWithName:component]; - } -#endif -} - -#pragma mark - Push Notifications - #if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC // Required to register for notifications diff --git a/packages/rn-tester/react-native.config.js b/packages/rn-tester/react-native.config.js index 099000c501058d..b3ad6adb66f61b 100644 --- a/packages/rn-tester/react-native.config.js +++ b/packages/rn-tester/react-native.config.js @@ -28,6 +28,7 @@ module.exports = { project: { ios: { sourceDir: '.', + unstable_reactLegacyComponentNames: ['RNTMyLegacyNativeView'], }, android: { sourceDir: '../../',