Skip to content

Commit

Permalink
build backwards compat API for runtime pointer
Browse files Browse the repository at this point in the history
Summary:
Changelog: [iOS][Added]

This is a pre-deprecated API 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.

changes as proposed in https://fb.workplace.com/groups/2158787827656681/posts/2306281142907348

Differential Revision: D53646413
  • Loading branch information
philIip authored and facebook-github-bot committed Feb 14, 2024
1 parent 8836513 commit ef280a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/react-native/React/Base/RCTBridgeProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions packages/react-native/React/Base/RCTBridgeProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @implementation RCTBridgeProxy {
RCTCallableJSModules *_callableJSModules;
void (^_dispatchToJSThread)(dispatch_block_t);
void (^_registerSegmentWithId)(NSNumber *, NSString *);
void *_runtime;
}

- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
Expand All @@ -36,15 +37,17 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
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;
}
Expand Down Expand Up @@ -75,10 +78,10 @@ - (Class)executorClass
* 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;
}

/**
Expand Down Expand Up @@ -162,7 +165,7 @@ - (void)enqueueJSCall:(NSString *)module

- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
self->_registerSegmentWithId(@(segmentId), path);
_registerSegmentWithId(@(segmentId), path);
}

- (id<RCTBridgeDelegate>)delegate
Expand Down

0 comments on commit ef280a4

Please sign in to comment.