Skip to content

Commit 7051827

Browse files
author
Riccardo Cipolleschi
committed
[TurboModule Setup] iOS: TurboModules: Ensure your App Provides an 'RCTCxxBridgeDelegate'
1 parent 3a5a17a commit 7051827

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

‎AwesomeApp/ios/AwesomeApp.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@
491491
"$(inherited)",
492492
"@executable_path/Frameworks",
493493
);
494+
OTHER_CPLUSPLUSFLAGS = (
495+
"$(OTHER_CFLAGS)",
496+
"-DFOLLY_NO_CONFIG",
497+
"-DFOLLY_MOBILE=1",
498+
"-DFOLLY_USE_LIBCPP=1",
499+
"-Wno-comma",
500+
"-Wno-shorten-64-to-32",
501+
);
494502
OTHER_LDFLAGS = (
495503
"$(inherited)",
496504
"-ObjC",
@@ -517,6 +525,14 @@
517525
"$(inherited)",
518526
"@executable_path/Frameworks",
519527
);
528+
OTHER_CPLUSPLUSFLAGS = (
529+
"$(OTHER_CFLAGS)",
530+
"-DFOLLY_NO_CONFIG",
531+
"-DFOLLY_MOBILE=1",
532+
"-DFOLLY_USE_LIBCPP=1",
533+
"-Wno-comma",
534+
"-Wno-shorten-64-to-32",
535+
);
520536
OTHER_LDFLAGS = (
521537
"$(inherited)",
522538
"-ObjC",

‎AwesomeApp/ios/AwesomeApp/AppDelegate.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#import <React/RCTBundleURLProvider.h>
55
#import <React/RCTRootView.h>
66

7+
#import <reacthermes/HermesExecutorFactory.h>
8+
#import <React/RCTCxxBridgeDelegate.h>
9+
#import <React/RCTJSIExecutorRuntimeInstaller.h>
10+
711
#ifdef FB_SONARKIT_ENABLED
812
#import <FlipperKit/FlipperClient.h>
913
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
@@ -23,6 +27,11 @@ static void InitializeFlipper(UIApplication *application) {
2327
}
2428
#endif
2529

30+
@interface AppDelegate () <RCTCxxBridgeDelegate> {
31+
// ...
32+
}
33+
@end
34+
2635
@implementation AppDelegate
2736

2837
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -59,4 +68,16 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
5968
#endif
6069
}
6170

71+
#pragma mark - RCTCxxBridgeDelegate
72+
73+
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
74+
{
75+
return std::make_unique<facebook::react::HermesExecutorFactory>(facebook::react::RCTJSIExecutorRuntimeInstaller([bridge](facebook::jsi::Runtime &runtime) {
76+
if (!bridge) {
77+
return;
78+
}
79+
})
80+
);
81+
}
82+
6283
@end

‎README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This branch contains all the step executed to:
1616
* [[Hermes] Use Hermes - iOS](#hermes-ios)
1717
* [[C++ iOS] iOS: Enable C++17 language feature support](#configure-cpp17)
1818
* [[C++ iOS] iOS: Use Objective-C++ (.mm extension)](#configure-objcpp)
19+
* [[TurboModule Setup] iOS: TurboModules: Ensure your App Provides an `RCTCxxBridgeDelegate`](#ios-tm)
1920

2021
## Steps
2122

@@ -170,3 +171,43 @@ This branch contains all the step executed to:
170171
1. Run `npx react-native run-ios`
171172

172173
**Note:** Renaming files in Xcode also updates the `xcodeproj` file automatically.
174+
175+
### <a name="ios-tm" /> [[TurboModule Setup] iOS: TurboModules: Ensure your App Provides an `RCTCxxBridgeDelegate`]()
176+
177+
1. Open the `AppDelegate.mm` file
178+
1. Add the following imports:
179+
```objc
180+
#import <reacthermes/HermesExecutorFactory.h>
181+
#import <React/RCTCxxBridgeDelegate.h>
182+
#import <React/RCTJSIExecutorRuntimeInstaller.h>
183+
``
184+
1. Add the following `@interface`, right before the `@implementation` keyword
185+
```obj-c
186+
@interface AppDelegate () <RCTCxxBridgeDelegate> {
187+
// ...
188+
}
189+
@end
190+
```
191+
1. Add the following function at the end of the file, before the `@end` keyword:
192+
```obj-c
193+
#pragma mark - RCTCxxBridgeDelegate
194+
195+
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
196+
{
197+
return std::make_unique<facebook::react::HermesExecutorFactory>(facebook::react::RCTJSIExecutorRuntimeInstaller([bridge](facebook::jsi::Runtime &runtime) {
198+
if (!bridge) {
199+
return;
200+
}
201+
})
202+
);
203+
}
204+
```
205+
1. In Xcode, select the `AwesomeApp` in the project navigator.
206+
1. Select `AwesomeApp` in the project panel
207+
1. Select the `Build Settings` tab
208+
1. Search for `CPLUSPLUS` in the filter text field
209+
1. Add the following flags to the `Other C++ Flags` field for both the `Debug` and the `Release` configurations:
210+
```sh
211+
-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32
212+
```
213+
1. From the `AwesomeApp` folder, run the app: `npx react-native ru-ios`

0 commit comments

Comments
 (0)