Skip to content

Commit

Permalink
Separatedly enable TM/Fabric (#35117)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Oct 29, 2022
1 parent 6621150 commit ec5a430
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
15 changes: 14 additions & 1 deletion Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* - (UIViewController *)createRootViewController;
* New Architecture:
* - (BOOL)concurrentRootEnabled
* - (BOOL)turboModuleEnabled;
* - (BOOL)fabricEnabled;
* - (NSDictionary *)prepareInitialProps
* - (Class)getModuleClassFromName:(const char *)name
* - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
Expand Down Expand Up @@ -106,12 +108,23 @@
@property (nonatomic, strong) RCTTurboModuleManager *turboModuleManager;
@property (nonatomic, strong) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
/// 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` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled;

/// This method controls whether the `turboModules` feature of the New Architecture is turned on or off.
///
/// @note: This is required to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the Turbo Native Module are enabled. Otherwise, it returns `false`.
- (BOOL)turboModuleEnabled;

/// This method controls whether the App will use the Fabric renderer of the New Architecture or not.
///
/// @return: `true` if the Fabric Renderer is enabled. Otherwise, it returns `false`.
- (BOOL)fabricEnabled;

@end
#endif
25 changes: 23 additions & 2 deletions Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ @implementation RCTAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTAppSetupPrepareApp(application);
BOOL enableTM = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = self.turboModuleEnabled;
#endif

RCTAppSetupPrepareApp(application, enableTM);

if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
Expand Down Expand Up @@ -94,7 +99,11 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initProps:(NSDictionary *)initProps
{
return RCTAppSetupDefaultRootView(bridge, moduleName, initProps);
BOOL enableFabric = NO;
#if RCT_NEW_ARCH_ENABLED
enableFabric = self.fabricEnabled;
#endif
return RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
}

- (UIViewController *)createRootViewController
Expand Down Expand Up @@ -138,6 +147,18 @@ - (Class)getModuleClassFromName:(const char *)name
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}

#pragma mark - New Arch Enabled settings

- (BOOL)turboModuleEnabled
{
return YES;
}

- (BOOL)fabricEnabled
{
return YES;
}

#endif

@end
8 changes: 6 additions & 2 deletions React/AppSetup/RCTAppSetupUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutor

RCT_EXTERN_C_BEGIN

void RCTAppSetupPrepareApp(UIApplication *application);
UIView *RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties);
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled);
UIView *RCTAppSetupDefaultRootView(
RCTBridge *bridge,
NSString *moduleName,
NSDictionary *initialProperties,
BOOL fabricEnabled);

RCT_EXTERN_C_END
18 changes: 10 additions & 8 deletions React/AppSetup/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,28 @@ static void InitializeFlipper(UIApplication *application)
}
#endif

void RCTAppSetupPrepareApp(UIApplication *application)
void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
{
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif

#if RCT_NEW_ARCH_ENABLED
RCTEnableTurboModule(YES);
RCTEnableTurboModule(turboModuleEnabled);
#endif
}

UIView *RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties)
UIView *
RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled)
{
#if RCT_NEW_ARCH_ENABLED
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
#else
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
if (fabricEnabled) {
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
}
#endif
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}

#if RCT_NEW_ARCH_ENABLED
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ SPEC CHECKSUMS:
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 05624e18294fd8279bb718e95d5bf2be311667ec
hermes-engine: cd15ebd246edff3a995ec666e898dd1cbdcaa10d
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
Expand Down

0 comments on commit ec5a430

Please sign in to comment.