From 5522d522bb868d71061091b0393a6bc0170c9c7e Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Mon, 11 Mar 2024 21:55:42 -0700 Subject: [PATCH] support jsCallInvoker in RCTBridgeProxy (#43314) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../React/Base/RCTBridgeProxy+Cxx.h | 20 +++++++++++++++++++ .../react-native/React/Base/RCTBridgeProxy.h | 2 ++ .../react-native/React/Base/RCTBridgeProxy.mm | 15 ++++++++++++++ .../platform/ios/ReactCommon/RCTInstance.mm | 14 +++++++------ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 packages/react-native/React/Base/RCTBridgeProxy+Cxx.h diff --git a/packages/react-native/React/Base/RCTBridgeProxy+Cxx.h b/packages/react-native/React/Base/RCTBridgeProxy+Cxx.h new file mode 100644 index 00000000000000..2748178a3dbb6e --- /dev/null +++ b/packages/react-native/React/Base/RCTBridgeProxy+Cxx.h @@ -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 +#endif + +#import "RCTBridgeProxy.h" + +@interface RCTBridgeProxy (Cxx) + +#ifdef __cplusplus +@property (nonatomic, readwrite) std::shared_ptr jsCallInvoker; +#endif + +@end diff --git a/packages/react-native/React/Base/RCTBridgeProxy.h b/packages/react-native/React/Base/RCTBridgeProxy.h index 79c75c3b491ae0..3a6de36473ee5b 100644 --- a/packages/react-native/React/Base/RCTBridgeProxy.h +++ b/packages/react-native/React/Base/RCTBridgeProxy.h @@ -15,6 +15,7 @@ @class RCTViewRegistry; @interface RCTBridgeProxy : NSProxy + - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry moduleRegistry:(RCTModuleRegistry *)moduleRegistry bundleManager:(RCTBundleManager *)bundleManager @@ -34,4 +35,5 @@ */ - (id)moduleForClass:(Class)moduleClass; - (id)moduleForName:(NSString *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad; + @end diff --git a/packages/react-native/React/Base/RCTBridgeProxy.mm b/packages/react-native/React/Base/RCTBridgeProxy.mm index 6c1e914c2f86b7..27637daf654c1c 100644 --- a/packages/react-native/React/Base/RCTBridgeProxy.mm +++ b/packages/react-native/React/Base/RCTBridgeProxy.mm @@ -6,10 +6,13 @@ */ #import "RCTBridgeProxy.h" +#import "RCTBridgeProxy+Cxx.h" + #import #import #import #import +#import #import using namespace facebook; @@ -21,6 +24,12 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel; - (void)forwardInvocation:(NSInvocation *)invocation; @end +@interface RCTBridgeProxy () + +@property (nonatomic, readwrite) std::shared_ptr jsCallInvoker; + +@end + @implementation RCTBridgeProxy { RCTUIManagerProxy *_uiManagerProxy; RCTModuleRegistry *_moduleRegistry; @@ -84,6 +93,12 @@ - (void *)runtime return _runtime; } +- (std::shared_ptr)jsCallInvoker +{ + [self logWarning:@"Please migrate to RuntimeExecutor" cmd:_cmd]; + return _jsCallInvoker; +} + /** * RCTModuleRegistry */ diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index 38f17f96129091..639cb889fab0e8 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -6,7 +6,6 @@ */ #import "RCTInstance.h" -#import #import @@ -16,6 +15,8 @@ #import #import #import +#import +#import #import #import #import @@ -256,6 +257,7 @@ - (void)_start RuntimeExecutor bufferedRuntimeExecutor = _reactInstance->getBufferedRuntimeExecutor(); timerManager->setRuntimeExecutor(bufferedRuntimeExecutor); + auto jsCallInvoker = make_shared(bufferedRuntimeExecutor); RCTBridgeProxy *bridgeProxy = [[RCTBridgeProxy alloc] initWithViewRegistry:_bridgeModuleDecorator.viewRegistry_DEPRECATED moduleRegistry:_bridgeModuleDecorator.moduleRegistry @@ -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(bufferedRuntimeExecutor)]; + _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridgeProxy:bridgeProxy + bridgeModuleDecorator:_bridgeModuleDecorator + delegate:self + jsInvoker:jsCallInvoker]; _turboModuleManager.runtimeHandler = self; #if RCT_DEV