build backwards compat API for runtime pointer (#43012)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43012

Changelog: [iOS][Added]

This implements the functionality to give access to the jsi::Runtime in iOS in bridgeless. In bridge, this value is a private selector on RCTBridge that is exposed via category. We build this into the backwards compatible RCTBridgeProxy here.

This should work out of the box in bridgeless if you are already retrieveing the pointer via the bridge. However, we recommend users to eventually migrate towards C++ TurboModule or the RuntimeExecutor if possible. This will be removed in the future.

Reviewed By: RSNara

Differential Revision: D53646413

fbshipit-source-id: a5584f22d433a580d537b8780a3bcd503680acb8
This commit is contained in:
Phillip Pan
2024-02-14 19:01:02 -08:00
committed by Facebook GitHub Bot
parent 315be8290d
commit 16276ce0f6
3 changed files with 17 additions and 12 deletions
@@ -20,7 +20,8 @@
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread
registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId NS_DESIGNATED_INITIALIZER;
registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId
runtime:(void *)runtime NS_DESIGNATED_INITIALIZER;
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel;
- (void)forwardInvocation:(NSInvocation *)invocation;
@@ -28,6 +28,7 @@ using namespace facebook;
RCTCallableJSModules *_callableJSModules;
void (^_dispatchToJSThread)(dispatch_block_t);
void (^_registerSegmentWithId)(NSNumber *, NSString *);
void *_runtime;
}
- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
@@ -36,15 +37,17 @@ using namespace facebook;
callableJSModules:(RCTCallableJSModules *)callableJSModules
dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread
registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId
runtime:(void *)runtime
{
self = [super self];
if (self) {
self->_uiManagerProxy = [[RCTUIManagerProxy alloc] initWithViewRegistry:viewRegistry];
self->_moduleRegistry = moduleRegistry;
self->_bundleManager = bundleManager;
self->_callableJSModules = callableJSModules;
self->_dispatchToJSThread = dispatchToJSThread;
self->_registerSegmentWithId = registerSegmentWithId;
_uiManagerProxy = [[RCTUIManagerProxy alloc] initWithViewRegistry:viewRegistry];
_moduleRegistry = moduleRegistry;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
_dispatchToJSThread = dispatchToJSThread;
_registerSegmentWithId = registerSegmentWithId;
_runtime = runtime;
}
return self;
}
@@ -75,10 +78,10 @@ using namespace facebook;
* Used By:
* - RCTBlobCollector
*/
- (jsi::Runtime *)runtime
- (void *)runtime
{
[self logWarning:@"This method is unsupported. Returning nullptr." cmd:_cmd];
return nullptr;
[self logWarning:@"Please migrate to C++ TurboModule or RuntimeExecutor." cmd:_cmd];
return _runtime;
}
/**
@@ -162,7 +165,7 @@ using namespace facebook;
- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
self->_registerSegmentWithId(@(segmentId), path);
_registerSegmentWithId(@(segmentId), path);
}
- (id<RCTBridgeDelegate>)delegate
@@ -263,7 +263,8 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
if (strongSelf && strongSelf->_valid) {
[strongSelf registerSegmentWithId:segmentId path:path];
}
}];
}
runtime:_reactInstance->getJavaScriptContext()];
[RCTBridge setCurrentBridge:(RCTBridge *)bridgeProxy];
// Set up TurboModules