Skip to content

Commit d7d58b5

Browse files
tido64Tommy Nguyen
authored andcommitted
fix(react-native-host): prepare for SwiftPM support
1 parent ee831f8 commit d7d58b5

11 files changed

Lines changed: 324 additions & 333 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rnx-kit/react-native-host": patch
3+
---
4+
5+
Moved public headers to `cocoa/include/ReactNativeHost/` and infer New
6+
Architecture from the React Native version in preparation for SwiftPM support.

‎packages/react-native-host/ReactNativeHost.podspec‎

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

3-
source_files = 'cocoa/*.{h,m,mm}'
4-
public_header_files = 'cocoa/{ReactNativeHost,RNXHostConfig}.h'
3+
source_files = 'cocoa/**/*.{h,m,mm}'
4+
public_header_files = 'cocoa/include/ReactNativeHost/*.h'
55

66
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
77
version = package['version']

‎packages/react-native-host/cocoa/RNXFeatureMacros.h‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
#pragma once
2+
3+
#if __has_include(<cxxreact/ReactNativeVersion.h>)
4+
#include <cxxreact/ReactNativeVersion.h>
5+
#define REACT_NATIVE_VERSION \
6+
REACT_NATIVE_VERSION_MAJOR * 1000000 + REACT_NATIVE_VERSION_MINOR * 1000 + \
7+
REACT_NATIVE_VERSION_PATCH
8+
#else
9+
#define REACT_NATIVE_VERSION 0
10+
#endif // __has_include(<cxxreact/ReactNativeVersion.h>)
11+
12+
// Force enable New Architecture if it cannot be disabled (>= 0.82). Build
13+
// systems that don't set preprocessor definitions (e.g. SwiftPM) rely on this.
14+
#if !USE_FABRIC && REACT_NATIVE_VERSION >= 82000
15+
#ifdef USE_FABRIC
16+
#undef USE_FABRIC
17+
#endif // USE_FABRIC
18+
#define USE_FABRIC 1
19+
#endif // !USE_FABRIC && REACT_NATIVE_VERSION >= 82000
20+
121
// Force enable Hermes if JSC is not available
222
#if !__has_include(<ReactCommon/RCTJscInstance.h>)
323
#ifdef USE_HERMES
@@ -16,15 +36,6 @@
1636

1737
#if USE_BRIDGELESS
1838

19-
#if __has_include(<cxxreact/ReactNativeVersion.h>)
20-
#include <cxxreact/ReactNativeVersion.h>
21-
#define REACT_NATIVE_VERSION \
22-
REACT_NATIVE_VERSION_MAJOR * 1000000 + REACT_NATIVE_VERSION_MINOR * 1000 + \
23-
REACT_NATIVE_VERSION_PATCH
24-
#else
25-
#define REACT_NATIVE_VERSION 0
26-
#endif // __has_include(<cxxreact/ReactNativeVersion.h>)
27-
2839
#if __has_include(<react/config/ReactNativeConfig.h>)
2940
#define USE_REACT_NATIVE_CONFIG 1
3041
#endif // __has_include(<react/config/ReactNativeConfig.h>)
@@ -39,21 +50,21 @@
3950

4051
#ifdef USE_FEATURE_FLAGS
4152

42-
#if __has_include(<react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>) // >= 0.80
53+
#if REACT_NATIVE_VERSION >= 80000
4354
#define USE_FEATURE_FLAGS_OSS_OVERRIDES 1
4455
#define USE_UNIFIED_FEATURE_FLAGS 1
4556
#elif __has_include(<React-RCTAppDelegate/RCTArchConfiguratorProtocol.h>) || __has_include(<React_RCTAppDelegate/RCTArchConfiguratorProtocol.h>)
4657
#define USE_UNIFIED_FEATURE_FLAGS 1
47-
#endif // __has_include(<react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>)
58+
#endif // REACT_NATIVE_VERSION >= 80000
4859

4960
#if !__has_include(<React-RCTAppDelegate/RCTReactNativeFactory.h>) && !__has_include(<React_RCTAppDelegate/RCTReactNativeFactory.h>)
5061
#define USE_VIEW_COMMAND_RACE_FIX 1
5162
#endif // !__has_include(<React-RCTAppDelegate/RCTReactNativeFactory.h>)
5263

5364
// `useShadowNodeStateOnClone` should be enabled from 0.79 and is on by default in 0.85
54-
#if REACT_NATIVE_VERSION < 85000 && (__has_include(<React-RCTAppDelegate/RCTJSRuntimeConfiguratorProtocol.h>) || __has_include(<React_RCTAppDelegate/RCTJSRuntimeConfiguratorProtocol.h>))
65+
#if REACT_NATIVE_VERSION >= 79000 && REACT_NATIVE_VERSION < 85000
5566
#define USE_UPDATE_RUNTIME_SHADOW_NODE_REFS_ON_COMMIT 1
56-
#endif // __has_include(<React-RCTAppDelegate/RCTJSRuntimeConfiguratorProtocol.h>)
67+
#endif // REACT_NATIVE_VERSION >= 79000 && REACT_NATIVE_VERSION < 85000
5768

5869
#if REACT_NATIVE_VERSION >= 87000
5970
#define RCT_REMOVE_LEGACY_ARCH 1

‎packages/react-native-host/cocoa/RNXHostReleaser.mm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#import <React/RCTUIManager.h>
55
#import <React/RCTUIManagerUtils.h>
66

7-
#import "ReactNativeHost.h"
7+
#import "include/ReactNativeHost/ReactNativeHost.h"
88

99
@implementation RNXHostReleaser {
1010
#if !TARGET_OS_OSX

‎packages/react-native-host/cocoa/RNXTurboModuleAdapter.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#import <Foundation/Foundation.h>
44
#include <cxxreact/JSExecutor.h>
55

6+
#import "RNXFeatureMacros.h"
7+
68
#if USE_FABRIC
79
#import <ReactCommon/RCTTurboModuleManager.h>
810
#endif // USE_FABRIC

‎packages/react-native-host/cocoa/ReactNativeHost+Private.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "ReactNativeHost.h"
1+
#import "include/ReactNativeHost/ReactNativeHost.h"
22

33
@class RCTHost;
44
@class RCTSurfacePresenter;

‎packages/react-native-host/cocoa/ReactNativeHost.mm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "ReactNativeHost.h"
1+
#import "include/ReactNativeHost/ReactNativeHost.h"
22

33
// clang-format off
44
#include "FollyConfig.h"
@@ -12,9 +12,9 @@
1212
#import "RNXBridgelessHeaders.h"
1313
#import "RNXFabricAdapter.h"
1414
#import "RNXFeatureMacros.h"
15-
#import "RNXHostConfig.h"
1615
#import "RNXHostReleaser.h"
1716
#import "RNXTurboModuleAdapter.h"
17+
#import "include/ReactNativeHost/RNXHostConfig.h"
1818

1919
#if !USE_BRIDGELESS
2020
#import <React/RCTCxxBridgeDelegate.h>

packages/react-native-host/cocoa/RNXHostConfig.h renamed to packages/react-native-host/cocoa/include/ReactNativeHost/RNXHostConfig.h

File renamed without changes.

packages/react-native-host/cocoa/ReactNativeHost.h renamed to packages/react-native-host/cocoa/include/ReactNativeHost/ReactNativeHost.h

File renamed without changes.

0 commit comments

Comments
 (0)