diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index 1f3d31f421531f..2d1b676a5ec846 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -77,6 +77,8 @@ @interface AppDelegate () } @end +static NSString *const kRNConcurrentRoot = @"concurrentRoot"; + @implementation AppDelegate - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -86,12 +88,7 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith _bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; // Appetizer.io params check - NSDictionary *initProps = @{}; - NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"]; - if (_routeUri) { - initProps = - @{@"exampleFromAppetizeParams" : [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]}; - } + NSDictionary *initProps = [self prepareInitialProps]; #ifdef RN_FABRIC_ENABLED _contextContainer = std::make_shared(); @@ -119,6 +116,28 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith return YES; } +- (BOOL)concurrentRootEnabled +{ + // Switch this bool to turn on and off the concurrent root + return true; +} + +- (NSDictionary *)prepareInitialProps +{ + NSMutableDictionary *initProps = [NSMutableDictionary new]; + + NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"]; + if (_routeUri) { + initProps[@"exampleFromAppetizeParams"] = [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]; + } + +#ifdef RCT_NEW_ARCH_ENABLED + initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); +#endif + + return initProps; +} + - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge { return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"packages/rn-tester/js/RNTesterApp.ios"]; diff --git a/template/ios/HelloWorld/AppDelegate.mm b/template/ios/HelloWorld/AppDelegate.mm index cef8d202e81c04..28475b9c49dde7 100644 --- a/template/ios/HelloWorld/AppDelegate.mm +++ b/template/ios/HelloWorld/AppDelegate.mm @@ -16,6 +16,8 @@ #import +static NSString *const kRNConcurrentRoot = @"concurrentRoot"; + @interface AppDelegate () { RCTTurboModuleManager *_turboModuleManager; RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; @@ -41,7 +43,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; #endif - UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"HelloWorld", nil); + NSDictionary *initProps = [self prepareInitialProps]; + UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"HelloWorld", initProps); if (@available(iOS 13.0, *)) { rootView.backgroundColor = [UIColor systemBackgroundColor]; @@ -57,6 +60,28 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return YES; } +/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. +/// +/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html +/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). +/// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`. +- (BOOL)concurrentRootEnabled +{ + // Switch this bool to turn on and off the concurrent root + return true; +} + +- (NSDictionary *)prepareInitialProps +{ + NSMutableDictionary *initProps = [NSMutableDictionary new]; + +#ifdef RCT_NEW_ARCH_ENABLED + initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); +#endif + + return initProps; +} + - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG