Skip to content

Commit 08284ba

Browse files
committed
ios: Add option to use RN's "New Architecture"
The bulk of this code only does anything if we enable New Arch. I'm not sure if some of the other bits might have some behavioral effect, though. This squashes together the following template changes upstream on the way to RN v0.68: facebook/react-native@73a04d145 Refactor the iOS app template to move setups to a helper class facebook/react-native@8ec0e6919 Add turbo module support in the default app template facebook/react-native@2e9a376c8 Add fabric option to the default app template. facebook/react-native@c0c543995 Rename the new architecture flag to RCT_NEW_ARCH_ENABLED facebook/react-native@1cd8f05ee Refactor app template setup util functions facebook/react-native@6a046fb9f Fix build issue for the new app template facebook/react-native@e330eee9c Add Other C++ flags when RCT_NEW_ARCH_ENABLE=1 facebook/react-native@ccd170809 … Consider relative to pwd installation root … They use new APIs introduced to RN at the same time, some of which get refactored further by the later commits; the last one fixes a bug a previous one introduced in the Podfile. It also includes: * Fixing the type of `rootView` back to the more specific `RCTRootView *`, rather than `UIView *`. We need the more specific type when setting its `.loadingView` property below. * Re-following Expo instructions for adding Expo to an existing RN app: https://docs.expo.dev/bare/installing-expo-modules/#configuration-for-ios This just requires the one hunk of that diff that changes the initializer for `rootView`.
1 parent 16ee11d commit 08284ba

File tree

4 files changed

+90
-27
lines changed

4 files changed

+90
-27
lines changed

ios/Podfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ
99
target 'ZulipMobile' do
1010
config = use_native_modules!
1111

12+
# Flags change depending on the env values.
13+
flags = get_default_flags()
14+
1215
use_react_native!(
1316
:path => config[:reactNativePath],
1417
# to enable hermes on iOS, change `false` to `true` and then install pods
15-
:hermes_enabled => false
18+
:hermes_enabled => flags[:hermes_enabled],
19+
:fabric_enabled => flags[:fabric_enabled],
20+
# An absolute path to your application root.
21+
:app_path => "#{Pod::Config.instance.installation_root}/.."
1622
)
1723

1824
# Enables Flipper.

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,6 @@ SPEC CHECKSUMS:
757757
Yoga: c4d61225a466f250c35c1ee78d2d0b3d41fe661c
758758
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
759759

760-
PODFILE CHECKSUM: 5246a27326b34ca5020f4cfdd2d084a266874427
760+
PODFILE CHECKSUM: 1576cc1dcc2b42d6d0484ee84b568d44a1a91346
761761

762762
COCOAPODS: 1.11.3

ios/ZulipMobile.xcodeproj/project.pbxproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
buildSettings = {
461461
ALWAYS_SEARCH_USER_PATHS = NO;
462462
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
463-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
463+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
464464
CLANG_CXX_LIBRARY = "libc++";
465465
CLANG_ENABLE_MODULES = YES;
466466
CLANG_ENABLE_OBJC_ARC = YES;
@@ -512,6 +512,12 @@
512512
);
513513
MTL_ENABLE_DEBUG_INFO = YES;
514514
ONLY_ACTIVE_ARCH = YES;
515+
OTHER_CPLUSPLUSFLAGS = (
516+
"$(OTHER_CFLAGS)",
517+
"-DFOLLY_NO_CONFIG",
518+
"-DFOLLY_MOBILE=1",
519+
"-DFOLLY_USE_LIBCPP=1",
520+
);
515521
PRODUCT_BUNDLE_IDENTIFIER = org.zulip.ZulipMobile;
516522
SDKROOT = iphoneos;
517523
};
@@ -522,7 +528,7 @@
522528
buildSettings = {
523529
ALWAYS_SEARCH_USER_PATHS = NO;
524530
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
525-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
531+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
526532
CLANG_CXX_LIBRARY = "libc++";
527533
CLANG_ENABLE_MODULES = YES;
528534
CLANG_ENABLE_OBJC_ARC = YES;
@@ -566,6 +572,12 @@
566572
"$(inherited)",
567573
);
568574
MTL_ENABLE_DEBUG_INFO = NO;
575+
OTHER_CPLUSPLUSFLAGS = (
576+
"$(OTHER_CFLAGS)",
577+
"-DFOLLY_NO_CONFIG",
578+
"-DFOLLY_MOBILE=1",
579+
"-DFOLLY_USE_LIBCPP=1",
580+
);
569581
PRODUCT_BUNDLE_IDENTIFIER = org.zulip.ZulipMobile;
570582
SDKROOT = iphoneos;
571583
VALIDATE_PRODUCT = YES;

ios/ZulipMobile/AppDelegate.mm

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,46 @@
99
#import <UserNotifications/UserNotifications.h>
1010
#import <RNCPushNotificationIOS.h>
1111

12-
#ifdef FB_SONARKIT_ENABLED
13-
#import <FlipperKit/FlipperClient.h>
14-
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
15-
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
16-
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
17-
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
18-
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
19-
20-
static void InitializeFlipper(UIApplication *application) {
21-
FlipperClient *client = [FlipperClient sharedClient];
22-
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
23-
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
24-
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
25-
[client addPlugin:[FlipperKitReactPlugin new]];
26-
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
27-
[client start];
28-
}
12+
#import <React/RCTAppSetupUtils.h>
13+
14+
#if RCT_NEW_ARCH_ENABLED
15+
#import <React/CoreModulesPlugins.h>
16+
#import <React/RCTCxxBridgeDelegate.h>
17+
#import <ReactCommon/RCTTurboModuleManager.h>
18+
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
19+
#import <React/RCTSurfacePresenter.h>
20+
#import <React/RCTSurfacePresenterBridgeAdapter.h>
21+
22+
#import <react/config/ReactNativeConfig.h>
23+
24+
@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
25+
RCTTurboModuleManager *_turboModuleManager;
26+
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
27+
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
28+
facebook::react::ContextContainer::Shared _contextContainer;
29+
}
30+
@end
2931
#endif
3032

3133
@implementation AppDelegate
3234

3335
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3436
{
35-
#ifdef FB_SONARKIT_ENABLED
36-
InitializeFlipper(application);
37-
#endif
37+
RCTAppSetupPrepareApp(application);
3838

3939
RCTSetLogThreshold(RCTLogLevelError);
4040

4141
RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
42-
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge
43-
moduleName:@"ZulipMobile"
44-
initialProperties:nil];
42+
43+
#if RCT_NEW_ARCH_ENABLED
44+
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
45+
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
46+
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
47+
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
48+
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
49+
#endif
50+
51+
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"ZulipMobile" initialProperties:nil];
4552

4653
UIView* loadingView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
4754
loadingView.backgroundColor = [UIColor colorNamed:@"Brand"];
@@ -140,4 +147,42 @@ -(void)userNotificationCenter:(UNUserNotificationCenter *)center
140147
);
141148
}
142149

150+
#if RCT_NEW_ARCH_ENABLED
151+
152+
#pragma mark - RCTCxxBridgeDelegate
153+
154+
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
155+
{
156+
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
157+
delegate:self
158+
jsInvoker:bridge.jsCallInvoker];
159+
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
160+
}
161+
162+
#pragma mark RCTTurboModuleManagerDelegate
163+
164+
- (Class)getModuleClassFromName:(const char *)name
165+
{
166+
return RCTCoreModulesClassProvider(name);
167+
}
168+
169+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
170+
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
171+
{
172+
return nullptr;
173+
}
174+
175+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
176+
initParams:(const facebook::react::ObjCTurboModule::InitParams &)params
177+
{
178+
return nullptr;
179+
}
180+
181+
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
182+
{
183+
return RCTAppSetupDefaultModuleFromClass(moduleClass);
184+
}
185+
186+
#endif
187+
143188
@end

0 commit comments

Comments
 (0)