Skip to content

Commit ec5a430

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Separatedly enable TM/Fabric (facebook#35117)
Summary: Pull Request resolved: facebook#35117 This mimics some behavior we have in Android that allow uesers to turn on selectively TM and Fabric. Notice that if fabric is enabled, TM must be enabled as well, otherwise the app won't work ## Changelog [iOS][Added] - Added the possibility to selectively enable TM and Fabric with the new Architecture Reviewed By: cortinico Differential Revision: D40794328 fbshipit-source-id: b7fc7bb819d05566dcd335832cab224f80b23346
1 parent 6621150 commit ec5a430

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
* - (UIViewController *)createRootViewController;
4444
* New Architecture:
4545
* - (BOOL)concurrentRootEnabled
46+
* - (BOOL)turboModuleEnabled;
47+
* - (BOOL)fabricEnabled;
4648
* - (NSDictionary *)prepareInitialProps
4749
* - (Class)getModuleClassFromName:(const char *)name
4850
* - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
@@ -106,12 +108,23 @@
106108
@property (nonatomic, strong) RCTTurboModuleManager *turboModuleManager;
107109
@property (nonatomic, strong) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
108110

109-
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
111+
/// This method controls whether the `concurrentRoot` feature of React18 is turned on or off.
110112
///
111113
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
112114
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
113115
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
114116
- (BOOL)concurrentRootEnabled;
115117

118+
/// This method controls whether the `turboModules` feature of the New Architecture is turned on or off.
119+
///
120+
/// @note: This is required to be rendering on Fabric (i.e. on the New Architecture).
121+
/// @return: `true` if the Turbo Native Module are enabled. Otherwise, it returns `false`.
122+
- (BOOL)turboModuleEnabled;
123+
124+
/// This method controls whether the App will use the Fabric renderer of the New Architecture or not.
125+
///
126+
/// @return: `true` if the Fabric Renderer is enabled. Otherwise, it returns `false`.
127+
- (BOOL)fabricEnabled;
128+
116129
@end
117130
#endif

Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ @implementation RCTAppDelegate
2929

3030
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3131
{
32-
RCTAppSetupPrepareApp(application);
32+
BOOL enableTM = NO;
33+
#if RCT_NEW_ARCH_ENABLED
34+
enableTM = self.turboModuleEnabled;
35+
#endif
36+
37+
RCTAppSetupPrepareApp(application, enableTM);
3338

3439
if (!self.bridge) {
3540
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
@@ -94,7 +99,11 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
9499
moduleName:(NSString *)moduleName
95100
initProps:(NSDictionary *)initProps
96101
{
97-
return RCTAppSetupDefaultRootView(bridge, moduleName, initProps);
102+
BOOL enableFabric = NO;
103+
#if RCT_NEW_ARCH_ENABLED
104+
enableFabric = self.fabricEnabled;
105+
#endif
106+
return RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
98107
}
99108

100109
- (UIViewController *)createRootViewController
@@ -138,6 +147,18 @@ - (Class)getModuleClassFromName:(const char *)name
138147
return RCTAppSetupDefaultModuleFromClass(moduleClass);
139148
}
140149

150+
#pragma mark - New Arch Enabled settings
151+
152+
- (BOOL)turboModuleEnabled
153+
{
154+
return YES;
155+
}
156+
157+
- (BOOL)fabricEnabled
158+
{
159+
return YES;
160+
}
161+
141162
#endif
142163

143164
@end

React/AppSetup/RCTAppSetupUtils.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutor
4242

4343
RCT_EXTERN_C_BEGIN
4444

45-
void RCTAppSetupPrepareApp(UIApplication *application);
46-
UIView *RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties);
45+
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled);
46+
UIView *RCTAppSetupDefaultRootView(
47+
RCTBridge *bridge,
48+
NSString *moduleName,
49+
NSDictionary *initialProperties,
50+
BOOL fabricEnabled);
4751

4852
RCT_EXTERN_C_END

React/AppSetup/RCTAppSetupUtils.mm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,28 @@ static void InitializeFlipper(UIApplication *application)
4444
}
4545
#endif
4646

47-
void RCTAppSetupPrepareApp(UIApplication *application)
47+
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
4848
{
4949
#ifdef FB_SONARKIT_ENABLED
5050
InitializeFlipper(application);
5151
#endif
5252

5353
#if RCT_NEW_ARCH_ENABLED
54-
RCTEnableTurboModule(YES);
54+
RCTEnableTurboModule(turboModuleEnabled);
5555
#endif
5656
}
5757

58-
UIView *RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties)
58+
UIView *
59+
RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled)
5960
{
6061
#if RCT_NEW_ARCH_ENABLED
61-
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge
62-
moduleName:moduleName
63-
initialProperties:initialProperties];
64-
#else
65-
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
62+
if (fabricEnabled) {
63+
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge
64+
moduleName:moduleName
65+
initialProperties:initialProperties];
66+
}
6667
#endif
68+
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
6769
}
6870

6971
#if RCT_NEW_ARCH_ENABLED

packages/rn-tester/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ SPEC CHECKSUMS:
945945
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
946946
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
947947
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
948-
hermes-engine: 05624e18294fd8279bb718e95d5bf2be311667ec
948+
hermes-engine: cd15ebd246edff3a995ec666e898dd1cbdcaa10d
949949
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
950950
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
951951
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda

0 commit comments

Comments
 (0)