Skip to content

Commit 753aee1

Browse files
zhongwuzwblakef
authored andcommitted
RNTester enable concurrent root when using Fabric (#41166)
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 [IOS] [FIXED] - RNTester enable concurrent root when using Fabric Pull Request resolved: #41166 Test Plan: Warning disappear. Reviewed By: cipolleschi Differential Revision: D50596693 Pulled By: javache fbshipit-source-id: d73a17cd137b3088405f86b739cb0ed7b5a9839e
1 parent 1a9994b commit 753aee1

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
* By default, it assigns the rootView to the view property of the rootViewController
101101
* If you are not using a simple UIViewController, then there could be other methods to use to setup the rootView.
102102
* For example: UISplitViewController requires `setViewController(_:for:)`
103-
*
104-
* @return: void
105103
*/
106104
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController;
107105

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ @interface RCTAppDelegate () <
4949

5050
#endif
5151

52+
static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
53+
{
54+
#ifdef RCT_NEW_ARCH_ENABLED
55+
NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new];
56+
// Hardcoding the Concurrent Root as it it not recommended to
57+
// have the concurrentRoot turned off when Fabric is enabled.
58+
mutableProps[kRNConcurrentRoot] = @(isFabricEnabled);
59+
return mutableProps;
60+
#else
61+
return initialProps;
62+
#endif
63+
}
64+
5265
@interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
5366
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
5467
}
@@ -76,10 +89,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
7689
{
7790
BOOL enableTM = NO;
7891
BOOL enableBridgeless = NO;
92+
BOOL fabricEnabled = NO;
7993
#if RCT_NEW_ARCH_ENABLED
8094
enableTM = self.turboModuleEnabled;
8195
enableBridgeless = self.bridgelessEnabled;
96+
fabricEnabled = [self fabricEnabled];
8297
#endif
98+
NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled);
8399

84100
RCTAppSetupPrepareApp(application, enableTM);
85101

@@ -88,7 +104,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
88104
if (enableBridgeless) {
89105
#if RCT_NEW_ARCH_ENABLED
90106
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
91-
RCTSetUseNativeViewConfigsInBridgelessMode([self fabricEnabled]);
107+
RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled);
92108

93109
// Enable TurboModule interop by default in Bridgeless mode
94110
RCTEnableTurboModuleInterop(YES);
@@ -97,8 +113,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
97113
[self createReactHost];
98114
[self unstable_registerLegacyComponents];
99115
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
100-
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName
101-
initialProperties:launchOptions];
116+
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps];
102117

103118
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
104119
initWithSurface:surface
@@ -118,7 +133,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
118133
[self unstable_registerLegacyComponents];
119134
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
120135
#endif
121-
NSDictionary *initProps = [self prepareInitialProps];
136+
122137
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
123138
}
124139
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
@@ -140,15 +155,7 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
140155

141156
- (NSDictionary *)prepareInitialProps
142157
{
143-
NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];
144-
145-
#ifdef RCT_NEW_ARCH_ENABLED
146-
// Hardcoding the Concurrent Root as it it not recommended to
147-
// have the concurrentRoot turned off when Fabric is enabled.
148-
initProps[kRNConcurrentRoot] = @([self fabricEnabled]);
149-
#endif
150-
151-
return initProps;
158+
return self.initialProps;
152159
}
153160

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

0 commit comments

Comments
 (0)