Skip to content

Commit 1fc231c

Browse files
committed
feat: pick up default config from RCT_NEW_ARCH_ENABLED
1 parent 9f0b8a4 commit 1fc231c

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ jobs:
44
analyse:
55
docker:
66
- image: cimg/node:current
7+
environment:
8+
SKIP_YARN_COREPACK_CHECK: 0
79
steps:
810
- checkout
911
- restore_cache:

ReactNativeBrownfield.podspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
require 'json'
22

3+
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
4+
new_arch_enabled_flag = (is_new_arch_enabled ? " -DRCT_NEW_ARCH_ENABLED" : "")
5+
other_cflags = "$(inherited)" + new_arch_enabled_flag
6+
37
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
48

59
Pod::Spec.new do |spec|
@@ -14,7 +18,9 @@ Pod::Spec.new do |spec|
1418

1519
# s.source = { :git => "[email protected]/michalchudziak/react-native-brownfield.git", :tag => "v#{s.version}" }
1620
spec.source = { :path => "." }
17-
spec.source_files = "ios/**/*.{h,m}"
21+
spec.source_files = "ios/**/*.{h,m,mm}"
22+
spec.compiler_flags = new_arch_enabled_flag
23+
spec.pod_target_xcconfig = { 'OTHER_CPLUSPLUSFLAGS' => other_cflags }
1824

1925
spec.dependency 'React'
20-
end
26+
end

ios/ReactNativeBrownfield.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ NS_ASSUME_NONNULL_BEGIN
1414
@property (nonatomic, copy) NSString *bundlePath;
1515
@property (nonatomic) RCTRootViewFactory* rootViewFactory;
1616

17+
/// This property controls whether the App will use the Fabric renderer of the New Architecture or not.
18+
@property (nonatomic, assign) BOOL fabricEnabled;
19+
20+
/// This property controls whether React Native's new initialization layer is enabled.
21+
@property (nonatomic, assign) BOOL bridgelessEnabled;
22+
23+
/// This method controls whether the `turboModules` feature of the New Architecture is turned on or off
24+
@property (nonatomic, assign) BOOL turboModuleEnabled;
25+
1726
+(ReactNativeBrownfield*)shared;
1827

1928
-(void)startReactNative;

ios/ReactNativeBrownfield.mm

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ @implementation ReactNativeBrownfield
99
@synthesize entryFile = _entryFile;
1010
@synthesize fallbackResource = _fallbackResource;
1111
@synthesize bundlePath = _bundlePath;
12-
@synthesize bridge;
1312

1413
+ (ReactNativeBrownfield*)shared {
1514
static ReactNativeBrownfield *sharedBridgeManager = nil;
@@ -27,10 +26,27 @@ - (id)init {
2726
_entryFile = @"index";
2827
_fallbackResource = nil;
2928
_bundlePath = @"main.jsbundle";
29+
30+
// Pick the default setting from RCT_NEW_ARCH_ENABLED flag.
31+
BOOL newArchEnabled = [self newArchEnabled];
32+
_fabricEnabled = newArchEnabled;
33+
_bridgelessEnabled = newArchEnabled;
34+
_turboModuleEnabled = newArchEnabled;
3035
}
3136
return self;
3237
}
3338

39+
- (BOOL)newArchEnabled
40+
{
41+
#if RCT_NEW_ARCH_ENABLED
42+
return YES;
43+
#else
44+
return NO;
45+
#endif
46+
}
47+
48+
49+
3450
- (void)startReactNative {
3551
[self startReactNative:nil];
3652
}
@@ -52,9 +68,9 @@ - (void)startReactNative:(void(^)(void))onBundleLoaded launchOptions:(NSDictiona
5268

5369
RCTRootViewFactoryConfiguration *configuration =
5470
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
55-
newArchEnabled:true
56-
turboModuleEnabled:true
57-
bridgelessEnabled:true];
71+
newArchEnabled:_fabricEnabled
72+
turboModuleEnabled:_turboModuleEnabled
73+
bridgelessEnabled:_bridgelessEnabled];
5874
_rootViewFactory = [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:nil];
5975

6076
if (onBundleLoaded != nil) {

0 commit comments

Comments
 (0)