Skip to content

Commit

Permalink
RNTester enable concurrent root when using Fabric (facebook#41166)
Browse files Browse the repository at this point in the history
Summary:
RNTester's `AppDelegate` override `prepareInitialProps` method of super class `RCTAppDelegate` https://github.com/facebook/react-native/blob/70acd3f7d9edae9e40cc4603bede9778da281a85/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L152, so we missed `concurrentRoot` initial prop.

![image](https://github.com/facebook/react-native/assets/5061845/12af5815-afe6-46f0-8107-54ca443b4962)

cc javache cipolleschi

## Changelog:

[IOS] [FIXED] - RNTester enable concurrent root when using Fabric

Pull Request resolved: facebook#41166

Test Plan: Warning disappear.

Reviewed By: cipolleschi

Differential Revision: D50596693

Pulled By: javache

fbshipit-source-id: d73a17cd137b3088405f86b739cb0ed7b5a9839e
  • Loading branch information
zhongwuzw authored and Othinn committed Oct 30, 2023
1 parent 1587dce commit 926c06b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@
* By default, it assigns the rootView to the view property of the rootViewController
* If you are not using a simple UIViewController, then there could be other methods to use to setup the rootView.
* For example: UISplitViewController requires `setViewController(_:for:)`
*
* @return: void
*/
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController;

Expand Down
31 changes: 19 additions & 12 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ @interface RCTAppDelegate () <

#endif

static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
{
#ifdef RCT_NEW_ARCH_ENABLED
NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new];
// Hardcoding the Concurrent Root as it it not recommended to
// have the concurrentRoot turned off when Fabric is enabled.
mutableProps[kRNConcurrentRoot] = @(isFabricEnabled);
return mutableProps;
#else
return initialProps;
#endif
}

@interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
}
Expand Down Expand Up @@ -80,18 +93,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
BOOL enableTM = NO;
BOOL enableBridgeless = NO;
BOOL fabricEnabled = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = self.turboModuleEnabled;
enableBridgeless = self.bridgelessEnabled;
fabricEnabled = [self fabricEnabled];
#endif
NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled);

RCTAppSetupPrepareApp(application, enableTM);

UIView *rootView;
if (enableBridgeless) {
#if RCT_NEW_ARCH_ENABLED
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
RCTSetUseNativeViewConfigsInBridgelessMode([self fabricEnabled]);
RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled);

// Enable TurboModule interop by default in Bridgeless mode
RCTEnableTurboModuleInterop(YES);
Expand All @@ -100,7 +116,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self createReactHost];
[self unstable_registerLegacyComponents];
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
NSDictionary *initProps = [self prepareInitialProps];
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps];

RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
Expand All @@ -121,7 +136,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self unstable_registerLegacyComponents];
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
#endif
NSDictionary *initProps = [self prepareInitialProps];

rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand All @@ -143,15 +158,7 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge

- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];

#ifdef RCT_NEW_ARCH_ENABLED
// Hardcoding the Concurrent Root as it it not recommended to
// have the concurrentRoot turned off when Fabric is enabled.
initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
#endif

return initProps;
return self.initialProps;
}

- (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
Expand Down

0 comments on commit 926c06b

Please sign in to comment.