Add a delegate hook for providing a different JS implementation
Reviewed By: javache Differential Revision: D5404876 fbshipit-source-id: d86ca9943b4b45616fc90bf14e8b0607d3cdb93c
This commit is contained in:
parent
d5fe05fd67
commit
05c4de0b51
|
@ -18,6 +18,7 @@
|
|||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTBridgeMethod.h>
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTCxxBridgeDelegate.h>
|
||||
#import <React/RCTCxxModule.h>
|
||||
#import <React/RCTCxxUtils.h>
|
||||
#import <React/RCTDevSettings.h>
|
||||
|
@ -279,21 +280,28 @@ struct RCTInstanceCallback : public InstanceCallback {
|
|||
// This doesn't really do anything. The real work happens in initializeBridge.
|
||||
_reactInstance.reset(new Instance);
|
||||
|
||||
// Prepare executor factory (shared_ptr for copy into block)
|
||||
__weak RCTCxxBridge *weakSelf = self;
|
||||
|
||||
// Prepare executor factory (shared_ptr for copy into block)
|
||||
std::shared_ptr<JSExecutorFactory> executorFactory;
|
||||
if (!self.executorClass) {
|
||||
BOOL useCustomJSC =
|
||||
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
|
||||
[self.delegate shouldBridgeUseCustomJSC:self];
|
||||
// The arg is a cache dir. It's not used with standard JSC.
|
||||
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
|
||||
("OwnerIdentity", "ReactNative")
|
||||
("UseCustomJSC", (bool)useCustomJSC)
|
||||
#if RCT_PROFILE
|
||||
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
|
||||
#endif
|
||||
));
|
||||
if ([self.delegate conformsToProtocol:@protocol(RCTCxxBridgeDelegate)]) {
|
||||
id<RCTCxxBridgeDelegate> cxxDelegate = (id<RCTCxxBridgeDelegate>) self.delegate;
|
||||
executorFactory = [cxxDelegate jsExecutorFactoryForBridge:self];
|
||||
}
|
||||
if (!executorFactory) {
|
||||
BOOL useCustomJSC =
|
||||
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
|
||||
[self.delegate shouldBridgeUseCustomJSC:self];
|
||||
// The arg is a cache dir. It's not used with standard JSC.
|
||||
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
|
||||
("OwnerIdentity", "ReactNative")
|
||||
("UseCustomJSC", (bool)useCustomJSC)
|
||||
#if RCT_PROFILE
|
||||
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
|
||||
#endif
|
||||
));
|
||||
}
|
||||
} else {
|
||||
id<RCTJavaScriptExecutor> objcExecutor = [self moduleForClass:self.executorClass];
|
||||
executorFactory.reset(new RCTObjcExecutorFactory(objcExecutor, ^(NSError *error) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#import <React/RCTBridgeDelegate.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JSExecutorFactory;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// This is a separate class so non-C++ implementations don't need to
|
||||
// take a C++ dependency.
|
||||
|
||||
@protocol RCTCxxBridgeDelegate <RCTBridgeDelegate>
|
||||
|
||||
/**
|
||||
* In the RCTCxxBridge, if this method is implemented, return a
|
||||
* ExecutorFactory instance which can be used to create the executor.
|
||||
* If not implemented, or returns an empty pointer, JSCExecutorFactory
|
||||
* will be used.
|
||||
*/
|
||||
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge;
|
||||
|
||||
@end
|
|
@ -54,6 +54,8 @@
|
|||
1339578B1DF76D3500EC27BE /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; };
|
||||
133CAE8E1B8E5CFD00F6AD92 /* RCTDatePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 133CAE8D1B8E5CFD00F6AD92 /* RCTDatePicker.m */; };
|
||||
13456E931ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 13456E921ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m */; };
|
||||
134D63C31F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 134D63C21F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h */; };
|
||||
134D63C41F1FEC65008872B5 /* RCTCxxBridgeDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 134D63C21F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h */; };
|
||||
13513F3C1B1F43F400FCE529 /* RCTProgressViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */; };
|
||||
135A9BFB1E7B0EAE00587AEB /* RCTJSCErrorHandling.h in Headers */ = {isa = PBXBuildFile; fileRef = 135A9BF91E7B0EAE00587AEB /* RCTJSCErrorHandling.h */; };
|
||||
135A9BFC1E7B0EAE00587AEB /* RCTJSCErrorHandling.mm in Sources */ = {isa = PBXBuildFile; fileRef = 135A9BFA1E7B0EAE00587AEB /* RCTJSCErrorHandling.mm */; };
|
||||
|
@ -1655,6 +1657,7 @@
|
|||
13456E921ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+CoreLocation.m"; sourceTree = "<group>"; };
|
||||
1345A83A1B265A0E00583190 /* RCTURLRequestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestDelegate.h; sourceTree = "<group>"; };
|
||||
1345A83B1B265A0E00583190 /* RCTURLRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestHandler.h; sourceTree = "<group>"; };
|
||||
134D63C21F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTCxxBridgeDelegate.h; sourceTree = "<group>"; };
|
||||
13513F3A1B1F43F400FCE529 /* RCTProgressViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTProgressViewManager.h; sourceTree = "<group>"; };
|
||||
13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTProgressViewManager.m; sourceTree = "<group>"; };
|
||||
135A9BF91E7B0EAE00587AEB /* RCTJSCErrorHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSCErrorHandling.h; sourceTree = "<group>"; };
|
||||
|
@ -2079,6 +2082,7 @@
|
|||
13134C721E296B2A00B9F3CB /* CxxBridge */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
134D63C21F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h */,
|
||||
3D7454B31E54786200E74ADD /* NSDataBigString.h */,
|
||||
3D7AA9C31E548CD5001955CF /* NSDataBigString.mm */,
|
||||
13134C741E296B2A00B9F3CB /* RCTCxxBridge.mm */,
|
||||
|
@ -2822,6 +2826,7 @@
|
|||
3D302F7E1DF828F800D6DDAE /* RCTNavigator.h in Headers */,
|
||||
3D302F7F1DF828F800D6DDAE /* RCTNavigatorManager.h in Headers */,
|
||||
130443DD1E401AF500D93A67 /* RCTConvert+Transform.h in Headers */,
|
||||
134D63C41F1FEC65008872B5 /* RCTCxxBridgeDelegate.h in Headers */,
|
||||
3D302F801DF828F800D6DDAE /* RCTNavItem.h in Headers */,
|
||||
C6194AAD1EF156280034D062 /* RCTPackagerConnectionBridgeConfig.h in Headers */,
|
||||
3D302F811DF828F800D6DDAE /* RCTNavItemManager.h in Headers */,
|
||||
|
@ -3119,6 +3124,7 @@
|
|||
A2440AA21DF8D854006E7BFC /* RCTReloadCommand.h in Headers */,
|
||||
3D80DA7C1DF820620028D040 /* RCTRefreshControlManager.h in Headers */,
|
||||
3D80DA7D1DF820620028D040 /* RCTRootShadowView.h in Headers */,
|
||||
134D63C31F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h in Headers */,
|
||||
3D80DA7E1DF820620028D040 /* RCTScrollableProtocol.h in Headers */,
|
||||
657734901EE8354A00A0E9EA /* RCTInspectorPackagerConnection.h in Headers */,
|
||||
3D7BFD1D1EA8E351008DFB7A /* RCTPackagerConnection.h in Headers */,
|
||||
|
|
Loading…
Reference in New Issue