Skip to content

Commit 9f0b8a4

Browse files
committed
feat: support new architecture & bridgeless on iOS
1 parent 862bd77 commit 9f0b8a4

File tree

4 files changed

+177
-33
lines changed

4 files changed

+177
-33
lines changed

example/swift/Podfile.lock

Lines changed: 135 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,72 @@ PODS:
935935
- React-Mapbuffer (0.74.2):
936936
- glog
937937
- React-debug
938-
- react-native-safe-area-context (4.7.1):
938+
- react-native-safe-area-context (4.10.5):
939+
- DoubleConversion
940+
- glog
941+
- hermes-engine
942+
- RCT-Folly (= 2024.01.01.00)
943+
- RCTRequired
944+
- RCTTypeSafety
945+
- React-Codegen
946+
- React-Core
947+
- React-debug
948+
- React-Fabric
949+
- React-featureflags
950+
- React-graphics
951+
- React-ImageManager
952+
- react-native-safe-area-context/common (= 4.10.5)
953+
- react-native-safe-area-context/fabric (= 4.10.5)
954+
- React-NativeModulesApple
955+
- React-RCTFabric
956+
- React-rendererdebug
957+
- React-utils
958+
- ReactCommon/turbomodule/bridging
959+
- ReactCommon/turbomodule/core
960+
- Yoga
961+
- react-native-safe-area-context/common (4.10.5):
962+
- DoubleConversion
963+
- glog
964+
- hermes-engine
965+
- RCT-Folly (= 2024.01.01.00)
966+
- RCTRequired
967+
- RCTTypeSafety
968+
- React-Codegen
939969
- React-Core
970+
- React-debug
971+
- React-Fabric
972+
- React-featureflags
973+
- React-graphics
974+
- React-ImageManager
975+
- React-NativeModulesApple
976+
- React-RCTFabric
977+
- React-rendererdebug
978+
- React-utils
979+
- ReactCommon/turbomodule/bridging
980+
- ReactCommon/turbomodule/core
981+
- Yoga
982+
- react-native-safe-area-context/fabric (4.10.5):
983+
- DoubleConversion
984+
- glog
985+
- hermes-engine
986+
- RCT-Folly (= 2024.01.01.00)
987+
- RCTRequired
988+
- RCTTypeSafety
989+
- React-Codegen
990+
- React-Core
991+
- React-debug
992+
- React-Fabric
993+
- React-featureflags
994+
- React-graphics
995+
- React-ImageManager
996+
- react-native-safe-area-context/common
997+
- React-NativeModulesApple
998+
- React-RCTFabric
999+
- React-rendererdebug
1000+
- React-utils
1001+
- ReactCommon/turbomodule/bridging
1002+
- ReactCommon/turbomodule/core
1003+
- Yoga
9401004
- React-nativeconfig (0.74.2)
9411005
- React-NativeModulesApple (0.74.2):
9421006
- glog
@@ -1166,13 +1230,74 @@ PODS:
11661230
- React-logger (= 0.74.2)
11671231
- React-perflogger (= 0.74.2)
11681232
- React-utils (= 0.74.2)
1169-
- ReactNativeBrownfield (0.0.3):
1233+
- ReactNativeBrownfield (0.1.0):
11701234
- React
1171-
- RNGestureHandler (2.12.1):
1235+
- RNGestureHandler (2.16.2):
1236+
- DoubleConversion
1237+
- glog
1238+
- hermes-engine
1239+
- RCT-Folly (= 2024.01.01.00)
1240+
- RCTRequired
1241+
- RCTTypeSafety
1242+
- React-Codegen
11721243
- React-Core
1173-
- RNScreens (3.24.0):
1244+
- React-debug
1245+
- React-Fabric
1246+
- React-featureflags
1247+
- React-graphics
1248+
- React-ImageManager
1249+
- React-NativeModulesApple
1250+
- React-RCTFabric
1251+
- React-rendererdebug
1252+
- React-utils
1253+
- ReactCommon/turbomodule/bridging
1254+
- ReactCommon/turbomodule/core
1255+
- Yoga
1256+
- RNScreens (3.32.0):
1257+
- DoubleConversion
1258+
- glog
1259+
- hermes-engine
1260+
- RCT-Folly (= 2024.01.01.00)
1261+
- RCTRequired
1262+
- RCTTypeSafety
1263+
- React-Codegen
11741264
- React-Core
1265+
- React-debug
1266+
- React-Fabric
1267+
- React-featureflags
1268+
- React-graphics
1269+
- React-ImageManager
1270+
- React-NativeModulesApple
1271+
- React-RCTFabric
11751272
- React-RCTImage
1273+
- React-rendererdebug
1274+
- React-utils
1275+
- ReactCommon/turbomodule/bridging
1276+
- ReactCommon/turbomodule/core
1277+
- RNScreens/common (= 3.32.0)
1278+
- Yoga
1279+
- RNScreens/common (3.32.0):
1280+
- DoubleConversion
1281+
- glog
1282+
- hermes-engine
1283+
- RCT-Folly (= 2024.01.01.00)
1284+
- RCTRequired
1285+
- RCTTypeSafety
1286+
- React-Codegen
1287+
- React-Core
1288+
- React-debug
1289+
- React-Fabric
1290+
- React-featureflags
1291+
- React-graphics
1292+
- React-ImageManager
1293+
- React-NativeModulesApple
1294+
- React-RCTFabric
1295+
- React-RCTImage
1296+
- React-rendererdebug
1297+
- React-utils
1298+
- ReactCommon/turbomodule/bridging
1299+
- ReactCommon/turbomodule/core
1300+
- Yoga
11761301
- SocketRocket (0.7.0)
11771302
- Yoga (0.0.0)
11781303

@@ -1392,15 +1517,15 @@ SPEC CHECKSUMS:
13921517
React-jsitracing: 0fa7f78d8fdda794667cb2e6f19c874c1cf31d7e
13931518
React-logger: 29fa3e048f5f67fe396bc08af7606426d9bd7b5d
13941519
React-Mapbuffer: bf56147c9775491e53122a94c423ac201417e326
1395-
react-native-safe-area-context: 9697629f7b2cda43cf52169bb7e0767d330648c2
1520+
react-native-safe-area-context: afa5d614d6b1b73b743c9261985876606560d128
13961521
React-nativeconfig: 9f223cd321823afdecf59ed00861ab2d69ee0fc1
13971522
React-NativeModulesApple: ff7efaff7098639db5631236cfd91d60abff04c0
13981523
React-perflogger: 32ed45d9cee02cf6639acae34251590dccd30994
13991524
React-RCTActionSheet: 19f967ddaea258182b56ef11437133b056ba2adf
14001525
React-RCTAnimation: d7f4137fc44a08bba465267ea7cb1dbdb7c4ec87
1401-
React-RCTAppDelegate: 2b3f4d8009796af209a0d496e73276b743acee08
1526+
React-RCTAppDelegate: dca95e1a6194f7ae06c2b5f1d5f891c61af00ec8
14021527
React-RCTBlob: c6c3e1e0251700b7bea036b893913f22e2b9cb47
1403-
React-RCTFabric: 93a3ea55169d19294f07092013c1c9ea7a015c9b
1528+
React-RCTFabric: a7874c54aea18f64677446efc5f839ec4fa5e931
14041529
React-RCTImage: 40528ab74a4fef0f0e2ee797a074b26d120b6cc6
14051530
React-RCTLinking: 385b5beb96749aae9ae1606746e883e1c9f8a6a7
14061531
React-RCTNetwork: ffc9f05bd8fa5b3bce562199ba41235ad0af645c
@@ -1416,9 +1541,9 @@ SPEC CHECKSUMS:
14161541
React-runtimescheduler: 56b642bf605ba5afa500d35790928fc1d51565ad
14171542
React-utils: 4476b7fcbbd95cfd002f3e778616155241d86e31
14181543
ReactCommon: ecad995f26e0d1e24061f60f4e5d74782f003f12
1419-
ReactNativeBrownfield: 0bc504532635a5bd52357da90809911304b3a5cd
1420-
RNGestureHandler: c0d04458598fcb26052494ae23dda8f8f5162b13
1421-
RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7
1544+
ReactNativeBrownfield: e2d42d8eae1211894757bb6862ed8d913c14ac47
1545+
RNGestureHandler: 156548e18203327173a764c6932a3f52e90cb9cd
1546+
RNScreens: d3d50aa84db4541eee00fbb1f32151030f56c510
14221547
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
14231548
Yoga: 2f71ecf38d934aecb366e686278102a51679c308
14241549

ios/ReactNativeBrownfield.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import <Foundation/Foundation.h>
22
#import <React/RCTBridge.h>
33
#import <React/RCTBridgeDelegate.h>
4+
#import <React-RCTAppDelegate/RCTRootViewFactory.h>
45

56
NS_ASSUME_NONNULL_BEGIN
67

@@ -11,14 +12,17 @@ NS_ASSUME_NONNULL_BEGIN
1112
@property (nonatomic, copy) NSString *entryFile;
1213
@property (nonatomic, copy, nullable) NSString *fallbackResource;
1314
@property (nonatomic, copy) NSString *bundlePath;
14-
@property (nonatomic) RCTBridge *bridge;
15+
@property (nonatomic) RCTRootViewFactory* rootViewFactory;
1516

1617
+(ReactNativeBrownfield*)shared;
1718

1819
-(void)startReactNative;
1920
-(void)startReactNative:(void(^)(void))onBundleLoaded;
2021
-(void)startReactNative:(void(^)(void))onBundleLoaded launchOptions:(NSDictionary *)launchOptions;
2122

23+
/// Return the bundle URL for the main bundle.
24+
- (NSURL *__nullable)bundleURL;
25+
2226
@end
2327

2428
NS_ASSUME_NONNULL_END

ios/ReactNativeBrownfield.m renamed to ios/ReactNativeBrownfield.mm

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import <Foundation/Foundation.h>
22
#import <React/RCTBundleURLProvider.h>
3+
#import <React-RCTAppDelegate/RCTRootViewFactory.h>
34

45
#import "ReactNativeBrownfield.h"
56

@@ -39,11 +40,22 @@ - (void)startReactNative:(void(^)(void))onBundleLoaded {
3940
}
4041

4142
- (void)startReactNative:(void(^)(void))onBundleLoaded launchOptions:(NSDictionary *)launchOptions {
42-
if (bridge != nil) {
43+
if (_rootViewFactory != nil) {
4344
return;
4445
}
4546

46-
bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
47+
__weak __typeof(self) weakSelf = self;
48+
RCTBundleURLBlock bundleUrlBlock = ^{
49+
ReactNativeBrownfield *strongSelf = weakSelf;
50+
return strongSelf.bundleURL;
51+
};
52+
53+
RCTRootViewFactoryConfiguration *configuration =
54+
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
55+
newArchEnabled:true
56+
turboModuleEnabled:true
57+
bridgelessEnabled:true];
58+
_rootViewFactory = [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:nil];
4759

4860
if (onBundleLoaded != nil) {
4961
_onBundleLoaded = [onBundleLoaded copy];
@@ -60,23 +72,27 @@ - (void)jsLoaded:(NSNotification*)notification {
6072

6173
#pragma mark - RCTBridgeDelegate Methods
6274

75+
- (NSURL *)bundleURL {
76+
#if DEBUG
77+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:_entryFile];
78+
#else
79+
NSArray<NSString *> *resourceURLComponents = [_bundlePath componentsSeparatedByString:@"."];
80+
NSRange withoutLast;
81+
82+
withoutLast.location = 0;
83+
withoutLast.length = [resourceURLComponents count] - 2;
84+
85+
NSArray<NSString *> *resourceURLComponentsWithoutExtension = [resourceURLComponents subarrayWithRange:withoutLast];
86+
87+
return [[NSBundle mainBundle]
88+
URLForResource:[resourceURLComponentsWithoutExtension componentsJoinedByString:@""]
89+
withExtension:resourceURLComponents[resourceURLComponents.count - 1]
90+
];
91+
#endif
92+
}
93+
6394
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
64-
#if DEBUG
65-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:_entryFile];
66-
#else
67-
NSArray<NSString *> *resourceURLComponents = [_bundlePath componentsSeparatedByString:@"."];
68-
NSRange withoutLast;
69-
70-
withoutLast.location = 0;
71-
withoutLast.length = [resourceURLComponents count] - 2;
72-
73-
NSArray<NSString *> *resourceURLComponentsWithoutExtension = [resourceURLComponents subarrayWithRange:withoutLast];
74-
75-
return [[NSBundle mainBundle]
76-
URLForResource:[resourceURLComponentsWithoutExtension componentsJoinedByString:@""]
77-
withExtension:resourceURLComponents[resourceURLComponents.count - 1]
78-
];
79-
#endif
95+
return self.bundleURL;
8096
}
8197

8298
@end

ios/ReactNativeViewController.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ -(instancetype)initWithModuleName:(NSString *)moduleName
2323
}
2424

2525
-(void)viewDidLoad {
26-
RCTBridge *bridge = [[ReactNativeBrownfield shared] bridge];
27-
if (bridge == nil) {
26+
RCTRootViewFactory *factory = [[ReactNativeBrownfield shared] rootViewFactory];
27+
if (factory == nil) {
2828
NSLog(@"Error: You need to start React Native in order to use ReactNativeViewController, make sure to run [[BridgeManager shared] startReactNative] before instantiating it.");
2929
return;
3030
}
3131

3232
if (_moduleName) {
33-
RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:_moduleName initialProperties:_initialProperties];
34-
self.view = reactView;
33+
self.view = [factory viewWithModuleName:_moduleName initialProperties:_initialProperties];
3534

3635
[[NSNotificationCenter defaultCenter]
3736
addObserver:self selector:@selector(togglePopGestureRecognizer:)

0 commit comments

Comments
 (0)