Skip to content

Commit

Permalink
build backwards compat API for runtime pointer (#43012)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
philIip authored and facebook-github-bot committed Feb 15, 2024
1 parent 315be82 commit 16276ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ - (void)_start
if (strongSelf && strongSelf->_valid) {
[strongSelf registerSegmentWithId:segmentId path:path];
}
}];
}
runtime:_reactInstance->getJavaScriptContext()];
[RCTBridge setCurrentBridge:(RCTBridge *)bridgeProxy];

// Set up TurboModules
Expand Down

0 comments on commit 16276ce

Please sign in to comment.