diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 1dbc570b382..fd6dee4c716 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -18,6 +18,7 @@ #import #import #import +#import #import #import #import @@ -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 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 cxxDelegate = (id) 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 objcExecutor = [self moduleForClass:self.executorClass]; executorFactory.reset(new RCTObjcExecutorFactory(objcExecutor, ^(NSError *error) { diff --git a/React/CxxBridge/RCTCxxBridgeDelegate.h b/React/CxxBridge/RCTCxxBridgeDelegate.h new file mode 100644 index 00000000000..ad7fc3d45b2 --- /dev/null +++ b/React/CxxBridge/RCTCxxBridgeDelegate.h @@ -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 + +#import + +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 + +/** + * 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)jsExecutorFactoryForBridge:(RCTBridge *)bridge; + +@end diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 6ba09329959..f511206a67f 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -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 = ""; }; 1345A83A1B265A0E00583190 /* RCTURLRequestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestDelegate.h; sourceTree = ""; }; 1345A83B1B265A0E00583190 /* RCTURLRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTURLRequestHandler.h; sourceTree = ""; }; + 134D63C21F1FEC4B008872B5 /* RCTCxxBridgeDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTCxxBridgeDelegate.h; sourceTree = ""; }; 13513F3A1B1F43F400FCE529 /* RCTProgressViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTProgressViewManager.h; sourceTree = ""; }; 13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTProgressViewManager.m; sourceTree = ""; }; 135A9BF91E7B0EAE00587AEB /* RCTJSCErrorHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSCErrorHandling.h; sourceTree = ""; }; @@ -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 */,