Skip to content

Commit

Permalink
support jsCallInvoker in RCTBridgeProxy (#43314)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43314

Changelog: [Internal]

making call invoker a breaking change to runtime executor in 0.74 seems to be causing a lot of discourse. let's simplify things and first add the callinvoker to the backwards compat layer

Reviewed By: cipolleschi

Differential Revision: D54404845

fbshipit-source-id: 983e86829030557033b95625dab9068492739417
  • Loading branch information
philIip authored and facebook-github-bot committed Mar 12, 2024
1 parent 620459a commit 5522d52
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
20 changes: 20 additions & 0 deletions packages/react-native/React/Base/RCTBridgeProxy+Cxx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#ifdef __cplusplus
#import <ReactCommon/CallInvoker.h>
#endif

#import "RCTBridgeProxy.h"

@interface RCTBridgeProxy (Cxx)

#ifdef __cplusplus
@property (nonatomic, readwrite) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;
#endif

@end
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTBridgeProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@class RCTViewRegistry;

@interface RCTBridgeProxy : NSProxy

- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
Expand All @@ -34,4 +35,5 @@
*/
- (id)moduleForClass:(Class)moduleClass;
- (id)moduleForName:(NSString *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad;

@end
15 changes: 15 additions & 0 deletions packages/react-native/React/Base/RCTBridgeProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

#import "RCTBridgeProxy.h"
#import "RCTBridgeProxy+Cxx.h"

#import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h>
#import <React/RCTLog.h>
#import <React/RCTUIManager.h>
#import <ReactCommon/CallInvoker.h>
#import <jsi/jsi.h>

using namespace facebook;
Expand All @@ -21,6 +24,12 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel;
- (void)forwardInvocation:(NSInvocation *)invocation;
@end

@interface RCTBridgeProxy ()

@property (nonatomic, readwrite) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;

@end

@implementation RCTBridgeProxy {
RCTUIManagerProxy *_uiManagerProxy;
RCTModuleRegistry *_moduleRegistry;
Expand Down Expand Up @@ -84,6 +93,12 @@ - (void *)runtime
return _runtime;
}

- (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker
{
[self logWarning:@"Please migrate to RuntimeExecutor" cmd:_cmd];
return _jsCallInvoker;
}

/**
* RCTModuleRegistry
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#import "RCTInstance.h"
#import <React/RCTBridgeProxy.h>

#import <memory>

Expand All @@ -16,6 +15,8 @@
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTBridgeModuleDecorator.h>
#import <React/RCTBridgeProxy+Cxx.h>
#import <React/RCTBridgeProxy.h>
#import <React/RCTComponentViewFactory.h>
#import <React/RCTConstants.h>
#import <React/RCTCxxUtils.h>
Expand Down Expand Up @@ -256,6 +257,7 @@ - (void)_start
RuntimeExecutor bufferedRuntimeExecutor = _reactInstance->getBufferedRuntimeExecutor();
timerManager->setRuntimeExecutor(bufferedRuntimeExecutor);

auto jsCallInvoker = make_shared<BridgelessJSCallInvoker>(bufferedRuntimeExecutor);
RCTBridgeProxy *bridgeProxy =
[[RCTBridgeProxy alloc] initWithViewRegistry:_bridgeModuleDecorator.viewRegistry_DEPRECATED
moduleRegistry:_bridgeModuleDecorator.moduleRegistry
Expand All @@ -274,14 +276,14 @@ - (void)_start
}
}
runtime:_reactInstance->getJavaScriptContext()];
bridgeProxy.jsCallInvoker = jsCallInvoker;
[RCTBridge setCurrentBridge:(RCTBridge *)bridgeProxy];

// Set up TurboModules
_turboModuleManager = [[RCTTurboModuleManager alloc]
initWithBridgeProxy:bridgeProxy
bridgeModuleDecorator:_bridgeModuleDecorator
delegate:self
jsInvoker:std::make_shared<BridgelessJSCallInvoker>(bufferedRuntimeExecutor)];
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridgeProxy:bridgeProxy
bridgeModuleDecorator:_bridgeModuleDecorator
delegate:self
jsInvoker:jsCallInvoker];
_turboModuleManager.runtimeHandler = self;

#if RCT_DEV
Expand Down

0 comments on commit 5522d52

Please sign in to comment.