mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
move callFunctionOnJSModule to public api (#37399)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37399 Changelog: [Internal] in this stack, i remove the `ReactInstanceForwarding` protocol. it is super lean and is only used by two classes, and the polymorphic behavior never comes into play because we never have a pointer to `id<ReactInstanceForwarding>` in our codebase. being able to call into JS from native is tablestakes behavior in userland, so i'm moving that to the public API. i also renamed it to be more clear that it's calling from native into JS, not the other way around. Reviewed By: cipolleschi Differential Revision: D45760090 fbshipit-source-id: 8ac99723796cb65891076e8e7d69aeefe3e94213
This commit is contained in:
committed by
Facebook GitHub Bot
parent
92fc503d56
commit
0ccc98d894
@@ -76,6 +76,12 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
|
||||
|
||||
- (RCTSurfacePresenter *)getSurfacePresenter FB_OBJC_DIRECT;
|
||||
|
||||
/**
|
||||
* Calls a method on a JS module that has been registered with `registerCallableModule`. Used to invoke a JS function
|
||||
* from platform code.
|
||||
*/
|
||||
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -140,7 +140,7 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Public API
|
||||
#pragma mark - Public
|
||||
|
||||
- (void)preload
|
||||
{
|
||||
@@ -199,6 +199,11 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
|
||||
return [_instance surfacePresenter];
|
||||
}
|
||||
|
||||
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
|
||||
{
|
||||
[_instance callFunctionOnJSModule:moduleName method:method args:args];
|
||||
}
|
||||
|
||||
#pragma mark - RCTReloadListener
|
||||
|
||||
- (void)didReceiveReloadCommand
|
||||
@@ -237,11 +242,6 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
|
||||
// early in startup, but could add some intelligent guards here.
|
||||
#pragma mark - ReactInstanceForwarding
|
||||
|
||||
- (void)callFunctionOnModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
|
||||
{
|
||||
[_instance callFunctionOnModule:moduleName method:method args:args];
|
||||
}
|
||||
|
||||
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
|
||||
{
|
||||
[_instance registerSegmentWithId:segmentId path:path];
|
||||
|
||||
@@ -45,12 +45,6 @@ FB_RUNTIME_PROTOCOL
|
||||
*/
|
||||
@protocol ReactInstanceForwarding
|
||||
|
||||
/**
|
||||
* Calls a method on a JS module that has been registered with `registerCallableModule`. Used to invoke a JS function
|
||||
* from platform code.
|
||||
*/
|
||||
- (void)callFunctionOnModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;
|
||||
|
||||
/**
|
||||
* Registers a new JS segment.
|
||||
*/
|
||||
@@ -77,6 +71,8 @@ typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)();
|
||||
jsErrorHandlingFunc:(facebook::react::JsErrorHandler::JsErrorHandlingFunc)jsErrorHandlingFunc
|
||||
FB_OBJC_DIRECT;
|
||||
|
||||
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@property (nonatomic, readonly, strong) RCTSurfacePresenter *surfacePresenter;
|
||||
|
||||
@@ -115,7 +115,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
|
||||
setBridgelessJSModuleMethodInvoker:^(
|
||||
NSString *moduleName, NSString *methodName, NSArray *args, dispatch_block_t onComplete) {
|
||||
// TODO: Make RCTInstance call onComplete
|
||||
[weakInstance callFunctionOnModule:moduleName method:methodName args:args];
|
||||
[weakInstance callFunctionOnJSModule:moduleName method:methodName args:args];
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -129,6 +129,14 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
|
||||
{
|
||||
if (_valid) {
|
||||
_reactInstance->callFunctionOnModule(
|
||||
[moduleName UTF8String], [method UTF8String], convertIdToFollyDynamic(args ?: @[]));
|
||||
}
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_invalidationMutex);
|
||||
@@ -191,14 +199,6 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
|
||||
|
||||
#pragma mark - ReactInstanceForwarding
|
||||
|
||||
- (void)callFunctionOnModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
|
||||
{
|
||||
if (_valid) {
|
||||
_reactInstance->callFunctionOnModule(
|
||||
[moduleName UTF8String], [method UTF8String], convertIdToFollyDynamic(args ?: @[]));
|
||||
}
|
||||
}
|
||||
|
||||
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
|
||||
{
|
||||
if (_valid) {
|
||||
|
||||
Reference in New Issue
Block a user