Cannot access `RuntimeExecutor` through `RCTCxxBridge` on iOS
See original GitHub issueDescription
It is currently not possible to access RuntimeExecutor
through RCTCxxBridge
on iOS even though it’s available through _reactInstance->getRuntimeExecutor()
:
@implementation RCTMyModule
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE()
- (void)initialize {
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;
// Cannot access `RuntimeExecutor` through `cxxBridge`
}
@end
On Android, RuntimeExecutor
can be accessed through CatalystInstance
:
public class MyModule extends ReactContextBaseJavaModule {
public MyModule(ReactApplicationContext reactContext) {
super(reactContext);
}
public void initialize() {
RuntimeExecutor runtimeExecutor = this
.getReactApplicationContext()
.getCatalystInstance()
.getRuntimeExecutor();
}
}
Should RCTCxxBridge
expose the underlying Instance
similar to how it’s done on Android or simply expose a runtimeExecutor
getter?
I’m currently using a shim based on CallInvoker
to work around this:
facebook::react::RuntimeExecutor runtimeExecutor =
[cxxBridge](std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
cxxBridge.jsCallInvoker->invokeAsync(
[cxxBridge, callback = std::move(callback)]() {
callback(*(facebook::jsi::Runtime *)(cxxBridge.runtime));
}
);
};
Version
0.66.4
Output of npx react-native info
System: OS: macOS 11.6.2 CPU: (4) x64 Intel® Core™ i5-4308U CPU @ 2.80GHz Memory: 77.92 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 17.2.0 - /usr/local/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.1.4 - /usr/local/bin/npm Watchman: 2021.12.06.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild Languages: Java: 17.0.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^17.0.2 => 17.0.2 react-native: ^0.66.4 => 0.66.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
- Create a native module for iOS.
- Access its associated
RCTBridge
and cast it toRCTCxxBridge
. - Notice how there’s no way to access the
RuntimeExecutor
hiding behind_reactInstance->getRuntimeExecutor()
.
Snack, code example, screenshot, or link to a repository
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
On a related note, I might be holding
RuntimeExecutor
wrong. I’m using it to install JSI bindings for a native module, but on Android, which uses_reactInstance->getRuntimeExecutor()
, I’m not seeing the bindings in the JavaScript context of the application:When the application loads,
__myFunction
isundefined
. It works just fine on iOS with theRuntimeExecutor
shim described previously.Edit: The cause has been identified in https://github.com/facebook/react-native/issues/32813#issuecomment-1020021633.
Is there anything I can do to help this issue along?