-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This is a Bridgeless-compatible API to allow our NativeModules to call JSModule methods. Changelog: [iOS][Added] - Introduce RCTCallableJSModules API for NativeModules Differential Revision: D28395448 fbshipit-source-id: b7929ba8b4cc4410361961b45efa23c76baacd24
- Loading branch information
1 parent
c6d77a8
commit ece373d
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTBridge.h" | ||
#import "RCTBridgeModule.h" | ||
|
||
@implementation RCTCallableJSModules { | ||
RCTBridgelessJSModuleMethodInvoker _bridgelessJSModuleMethodInvoker; | ||
__weak RCTBridge *_bridge; | ||
} | ||
|
||
- (void)setBridge:(RCTBridge *)bridge | ||
{ | ||
_bridge = bridge; | ||
} | ||
|
||
- (void)setBridgelessJSModuleMethodInvoker:(RCTBridgelessJSModuleMethodInvoker)bridgelessJSModuleMethodInvoker | ||
{ | ||
_bridgelessJSModuleMethodInvoker = bridgelessJSModuleMethodInvoker; | ||
} | ||
|
||
- (void)invokeModule:(NSString *)moduleName method:(NSString *)methodName withArgs:(NSArray *)args | ||
{ | ||
[self invokeModule:moduleName method:methodName withArgs:args onComplete:NULL]; | ||
} | ||
|
||
- (void)invokeModule:(NSString *)moduleName | ||
method:(NSString *)methodName | ||
withArgs:(NSArray *)args | ||
onComplete:(dispatch_block_t)onComplete | ||
{ | ||
RCTBridge *bridge = _bridge; | ||
if (bridge) { | ||
[bridge enqueueJSCall:moduleName method:methodName args:args completion:onComplete]; | ||
return; | ||
} | ||
|
||
if (_bridgelessJSModuleMethodInvoker) { | ||
_bridgelessJSModuleMethodInvoker(moduleName, methodName, args, onComplete); | ||
} | ||
} | ||
|
||
@end |