Skip to content

Commit

Permalink
Add fabric option to the default app template.
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal] Added fabric option to the default app template.

Use RCT_TM_FABRIC_ENABLED C++ flag to enable fabric.

Reviewed By: sammy-SC

Differential Revision: D33052956

fbshipit-source-id: 28313829c80abcf02baa521bdb0b70213c94a97f
  • Loading branch information
sota000 authored and facebook-github-bot committed Dec 16, 2021
1 parent 8ec0e69 commit 2e9a376
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 3 additions & 3 deletions React/AppSetup/RCTAppSetupUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

@interface RCTAppSetupUtils : NSObject
+ (void)prepareApp:(UIApplication *_Nonnull)application;
+ (RCTRootView *_Nonnull)defaultRootViewWithBridge:(RCTBridge *_Nonnull)bridge
moduleName:(NSString *_Nonnull)moduleName
initialProperties:(nullable NSDictionary *)initialProperties;
+ (UIView *_Nonnull)defaultRootViewWithBridge:(RCTBridge *_Nonnull)bridge
moduleName:(NSString *_Nonnull)moduleName
initialProperties:(nullable NSDictionary *)initialProperties;

#if RCT_TM_FABRIC_ENABLED
+ (id<RCTTurboModule> _Nonnull)defaultModuleInstanceFromClass:(Class _Nonnull)moduleClass;
Expand Down
16 changes: 13 additions & 3 deletions React/AppSetup/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "RCTAppSetupUtils.h"

#if RCT_TM_FABRIC_ENABLED
// Turbo Module
#import <React/CoreModulesPlugins.h>
#import <React/RCTDataRequestHandler.h>
#import <React/RCTFileRequestHandler.h>
Expand All @@ -17,6 +18,9 @@
#import <React/RCTJSIExecutorRuntimeInstaller.h>
#import <React/RCTLocalAssetImageLoader.h>
#import <React/RCTNetworking.h>

// Fabric
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#endif

#ifdef FB_SONARKIT_ENABLED
Expand Down Expand Up @@ -53,11 +57,17 @@ + (void)prepareApp:(UIApplication *)application
#endif
}

+ (RCTRootView *)defaultRootViewWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
+ (UIView *)defaultRootViewWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
#if RCT_TM_FABRIC_ENABLED
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
#else
return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
#endif
}

#if RCT_TM_FABRIC_ENABLED
Expand Down
19 changes: 18 additions & 1 deletion template/ios/HelloWorld/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>

#import <react/config/ReactNativeConfig.h>

@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
@end
#endif
Expand All @@ -24,7 +32,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[RCTAppSetupUtils prepareApp: application];

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [RCTAppSetupUtils defaultRootViewWithBridge:bridge

#if RCT_TM_FABRIC_ENABLED
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif

UIView *rootView = [RCTAppSetupUtils defaultRootViewWithBridge:bridge
moduleName:@"HelloWorld"
initialProperties:nil];

Expand Down

0 comments on commit 2e9a376

Please sign in to comment.