Skip to content

Commit c652815

Browse files
javachemeta-codesync[bot]
authored andcommitted
Compile out RCTCxxBridge when legacy arch is disabled (#56837)
Summary: Pull Request resolved: #56837 Fully remove the symbols for RCTCxxBridge when remove-legacy-arch is enabled. Changelog: [iOS][Breaking] Removing further legacy arch symbols such as RCTCxxBridge Reviewed By: christophpurrer Differential Revision: D105167968 fbshipit-source-id: 8210918bde769a8db30d45ab96b793517f916a86
1 parent 2574863 commit c652815

11 files changed

Lines changed: 36 additions & 81 deletions

File tree

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,20 @@ __attribute__((deprecated(
6666
/// The window object, used to render the UViewControllers
6767
@property (nonatomic, strong, nonnull) UIWindow *window;
6868

69+
#if !defined(RCT_REMOVE_LEGACY_ARCH)
6970
@property (nonatomic, nullable) RCTBridge *bridge
7071
__attribute__((deprecated("The bridge is deprecated and will be removed when removing the legacy architecture.")));
72+
@property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter __attribute__((
73+
deprecated("The bridge adapter is deprecated and will be removed when removing the legacy architecture.")));
74+
#endif
75+
7176
@property (nonatomic, strong, nullable) NSString *moduleName;
7277
@property (nonatomic, strong, nullable) NSDictionary *initialProps;
7378
@property (nonatomic, strong) RCTReactNativeFactory *reactNativeFactory;
7479

7580
/// If `automaticallyLoadReactNativeWindow` is set to `true`, the React Native window will be loaded automatically.
7681
@property (nonatomic, assign) BOOL automaticallyLoadReactNativeWindow;
7782

78-
@property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter __attribute__((
79-
deprecated("The bridge adapter is deprecated and will be removed when removing the legacy architecture.")));
80-
;
81-
8283
- (RCTRootViewFactory *)rootViewFactory;
8384

8485
@end

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ - (RCTRootViewFactory *)rootViewFactory
6767
return self.reactNativeFactory.rootViewFactory;
6868
}
6969

70+
#if !defined(RCT_REMOVE_LEGACY_ARCH)
7071
- (RCTBridge *)bridge
7172
{
7273
return self.rootViewFactory.bridge;
@@ -86,5 +87,6 @@ - (void)setBridgeAdapter:(RCTSurfacePresenterBridgeAdapter *)bridgeAdapter
8687
{
8788
self.reactNativeFactory.rootViewFactory.bridgeAdapter = bridgeAdapter;
8889
}
90+
#endif
8991

9092
@end

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ typedef NS_ENUM(NSInteger, RCTReleaseLevel) { Canary, Experimental, Stable };
108108
initialProperties:(NSDictionary *_Nullable)initialProperties
109109
launchOptions:(NSDictionary *_Nullable)launchOptions;
110110

111+
#if !defined(RCT_REMOVE_LEGACY_ARCH)
111112
@property (nonatomic, nullable) RCTBridge *bridge
112113
__attribute__((deprecated("The bridge is deprecated and will be removed when removing the legacy architecture.")));
113-
@property (nonatomic, strong, nonnull) RCTRootViewFactory *rootViewFactory;
114-
115114
@property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter __attribute__((
116115
deprecated("The bridgeAdapter is deprecated and will be removed when removing the legacy architecture.")));
117-
;
116+
#endif
117+
118+
@property (nonatomic, strong, nonnull) RCTRootViewFactory *rootViewFactory;
118119

119120
@property (nonatomic, weak) id<RCTReactNativeFactoryDelegate> delegate;
120121

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,12 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
184184
*/
185185
@interface RCTRootViewFactory : NSObject
186186

187+
#if !defined(RCT_REMOVE_LEGACY_ARCH)
187188
@property (nonatomic, strong, nullable) RCTBridge *bridge;
188-
@property (nonatomic, strong, nullable) RCTHost *reactHost;
189189
@property (nonatomic, strong, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter;
190+
#endif
191+
192+
@property (nonatomic, strong, nullable) RCTHost *reactHost;
190193

191194
- (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configuration
192195
andTurboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate> _Nullable)turboModuleManagerDelegate;

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
*/
77

88
#import "RCTRootViewFactory.h"
9-
#import <React/RCTCxxBridgeDelegate.h>
109
#import <React/RCTDevMenu.h>
1110
#import <React/RCTLog.h>
1211
#import <React/RCTRootView.h>
13-
#import <React/RCTSurfacePresenterBridgeAdapter.h>
1412
#import <React/RCTUtils.h>
1513
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
1614
#import "RCTAppDelegate.h"
@@ -90,7 +88,7 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
9088

9189
@end
9290

93-
@interface RCTRootViewFactory () <RCTCxxBridgeDelegate> {
91+
@interface RCTRootViewFactory () {
9492
std::shared_ptr<const facebook::react::ContextContainer> _contextContainer;
9593
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
9694
}
@@ -201,63 +199,6 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
201199
return surfaceHostingProxyRootView;
202200
}
203201

204-
- (RCTBridge *)createBridgeWithDelegate:(id<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
205-
{
206-
return [[RCTBridge alloc] initWithDelegate:delegate launchOptions:launchOptions];
207-
}
208-
209-
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
210-
moduleName:(NSString *)moduleName
211-
initProps:(NSDictionary *)initProps
212-
{
213-
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);
214-
#if !TARGET_OS_TV
215-
rootView.backgroundColor = [UIColor systemBackgroundColor];
216-
#else
217-
rootView.backgroundColor = [UIColor blackColor];
218-
#endif
219-
return rootView;
220-
}
221-
222-
#pragma mark - RCTCxxBridgeDelegate
223-
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
224-
{
225-
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
226-
227-
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
228-
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
229-
RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
230-
delegate:_turboModuleManagerDelegate
231-
jsInvoker:callInvoker];
232-
_contextContainer->erase(facebook::react::RuntimeSchedulerKey);
233-
_contextContainer->insert(facebook::react::RuntimeSchedulerKey, _runtimeScheduler);
234-
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
235-
}
236-
237-
- (void)createBridgeIfNeeded:(NSDictionary *)launchOptions
238-
{
239-
if (self.bridge != nil) {
240-
return;
241-
}
242-
243-
if (self->_configuration.createBridgeWithDelegate != nil) {
244-
self.bridge = self->_configuration.createBridgeWithDelegate(self, launchOptions);
245-
} else {
246-
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
247-
}
248-
}
249-
250-
- (void)createBridgeAdapterIfNeeded
251-
{
252-
if (self.bridgeAdapter != nullptr) {
253-
return;
254-
}
255-
256-
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
257-
contextContainer:_contextContainer];
258-
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
259-
}
260-
261202
#pragma mark - New Arch Utilities
262203

263204
- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions
@@ -324,6 +265,7 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
324265
return nil;
325266
}
326267

268+
#ifndef RCT_REMOVE_LEGACY_ARCH
327269
- (NSDictionary<NSString *, Class> *)extraLazyModuleClassesForBridge:(RCTBridge *)bridge
328270
{
329271
if (_configuration.extraLazyModuleClassesForBridge != nil) {
@@ -363,6 +305,7 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge
363305
_configuration.loadSourceForBridgeWithProgress(bridge, onProgress, loadCallback);
364306
}
365307
}
308+
#endif
366309

367310
- (NSURL *)bundleURL
368311
{

packages/react-native/React/Base/RCTBridge+Private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ RCT_EXTERN void RCTRegisterModule(Class);
145145

146146
@end
147147

148+
#if !defined(RCT_REMOVE_LEGACY_ARCH)
148149
@interface RCTCxxBridge : RCTBridge
149150

150151
// TODO(cjhopman): this seems unsafe unless we require that it is only called on the main js queue.
151152
@property (nonatomic, readonly) void *runtime;
152153

153-
#ifndef RCT_REMOVE_LEGACY_ARCH
154154
- (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER
155155
__deprecated_msg("This API will be removed along with the legacy architecture.");
156-
#endif // RCT_REMOVE_LEGACY_ARCH
157156

158157
@end
158+
#endif // RCT_REMOVE_LEGACY_ARCH

packages/react-native/React/Base/RCTBridgeProxy.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,11 @@ - (RCTBridgeProxy *)object
387387
*/
388388
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel;
389389
{
390+
#ifndef RCT_REMOVE_LEGACY_ARCH
390391
return [RCTCxxBridge instanceMethodSignatureForSelector:sel];
392+
#else
393+
return [RCTBridge instanceMethodSignatureForSelector:sel];
394+
#endif
391395
}
392396

393397
- (void)forwardInvocation:(NSInvocation *)invocation

packages/react-native/React/CxxBridge/RCTCxxBridge.mm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,4 @@ - (RCTCallInvoker *)callInvokerForModuleData:(RCTModuleData *)moduleData
15661566

15671567
@end
15681568

1569-
#else // RCT_REMOVE_LEGACY_ARCH
1570-
@implementation RCTCxxBridge
1571-
@end
15721569
#endif // RCT_REMOVE_LEGACY_ARCH

packages/react-native/React/Fabric/RCTSurfacePresenterBridgeAdapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515
@class RCTSurfacePresenter;
1616
@class RCTBridge;
1717

18+
#ifndef RCT_REMOVE_LEGACY_ARCH
1819
facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge);
1920

2021
/*
@@ -39,5 +40,6 @@ facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
3940
@property (nonatomic, weak) RCTBridge *bridge;
4041

4142
@end
43+
#endif
4244

4345
NS_ASSUME_NONNULL_END

packages/react-native/React/Fabric/RCTSurfacePresenterBridgeAdapter.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
using namespace facebook::react;
2626

27+
#ifndef RCT_REMOVE_LEGACY_ARCH
2728
@interface RCTBridge ()
28-
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
2929
- (void)invokeAsync:(std::function<void()> &&)func;
3030
@end
3131

@@ -203,3 +203,4 @@ - (void)handleJavaScriptDidLoadNotification:(NSNotification *)notification
203203
}
204204

205205
@end
206+
#endif

0 commit comments

Comments
 (0)