mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 22:41:56 +08:00
Add support for new ios bridge to FBReactBridgeJSExecutor
Reviewed By: javache Differential Revision: D3897535 fbshipit-source-id: 35bdaf885b03c0c95017a68b69f1f506e6943f2b
This commit is contained in:
committed by
Facebook Github Bot
parent
441d146b7b
commit
af5c8a8fd2
@@ -778,6 +778,48 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||
} queue:RCTJSThread];
|
||||
}
|
||||
|
||||
/**
|
||||
* JS thread only
|
||||
*/
|
||||
- (JSValue *)callFunctionOnModule:(NSString *)module
|
||||
method:(NSString *)method
|
||||
arguments:(NSArray *)arguments
|
||||
error:(NSError **)error
|
||||
{
|
||||
RCTJSCExecutor *jsExecutor = (RCTJSCExecutor *)_javaScriptExecutor;
|
||||
if (![jsExecutor isKindOfClass:[RCTJSCExecutor class]]) {
|
||||
RCTLogWarn(@"FBReactBridgeJSExecutor is only supported when running in JSC");
|
||||
return nil;
|
||||
}
|
||||
|
||||
__block JSValue *jsResult = nil;
|
||||
|
||||
RCTAssertJSThread();
|
||||
RCT_PROFILE_BEGIN_EVENT(0, @"callFunctionOnModule", (@{ @"module": module, @"method": method }));
|
||||
[jsExecutor callFunctionOnModule:module
|
||||
method:method
|
||||
arguments:arguments
|
||||
jsValueCallback:^(JSValue *result, NSError *jsError) {
|
||||
if (error) {
|
||||
*error = jsError;
|
||||
}
|
||||
|
||||
JSValue *length = result[@"length"];
|
||||
RCTAssert([length isNumber] && [length toUInt32] == 2,
|
||||
@"Return value of a callFunction must be an array of size 2");
|
||||
|
||||
jsResult = [result valueAtIndex:0];
|
||||
|
||||
NSArray *nativeModuleCalls = [[result valueAtIndex:1] toArray];
|
||||
[self handleBuffer:nativeModuleCalls batchEnded:YES];
|
||||
}];
|
||||
|
||||
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call");
|
||||
|
||||
return jsResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Private hack to support `setTimeout(fn, 0)`
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#import "RCTFrameUpdate.h"
|
||||
#import "RCTInvalidating.h"
|
||||
|
||||
@class JSValue;
|
||||
@class RCTBridge;
|
||||
@class RCTEventDispatcher;
|
||||
@class RCTPerformanceLogger;
|
||||
@@ -103,6 +104,21 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
|
||||
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
|
||||
- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion;
|
||||
|
||||
/**
|
||||
* This method is used to call functions in the JavaScript application context
|
||||
* synchronously. This is intended for use by applications which do their own
|
||||
* thread management and are careful to manage multi-threaded access to the JSVM.
|
||||
* See also -[RCTBridgeDelgate shouldBridgeLoadJavaScriptSynchronously], which
|
||||
* may be needed to ensure that any requires JS code is loaded before this method
|
||||
* is called. If the underlying executor is not JSC, this will return nil. Safe
|
||||
* to call from any thread.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
- (JSValue *)callFunctionOnModule:(NSString *)module
|
||||
method:(NSString *)method
|
||||
arguments:(NSArray *)arguments
|
||||
error:(NSError **)error;
|
||||
|
||||
/**
|
||||
* Retrieve a bridge module instance by name or class. Note that modules are
|
||||
|
||||
@@ -351,4 +351,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
[self.batchedBridge enqueueCallback:cbID args:args];
|
||||
}
|
||||
|
||||
- (JSValue *)callFunctionOnModule:(NSString *)module
|
||||
method:(NSString *)method
|
||||
arguments:(NSArray *)arguments
|
||||
error:(NSError **)error
|
||||
{
|
||||
return [self.batchedBridge callFunctionOnModule:module method:method arguments:arguments error:error];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user