Skip to content

Commit

Permalink
Fix hermes executor not available when use_frameworks is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Jul 19, 2022
1 parent 1d997ce commit 78ab43b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
18 changes: 3 additions & 15 deletions React/AppSetup/RCTAppSetupUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@

#if RCT_NEW_ARCH_ENABLED

#ifndef RCT_USE_HERMES
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
#define RCT_USE_HERMES 1
#else
#define RCT_USE_HERMES 0
#endif
#endif

#if RCT_USE_HERMES
#import <reacthermes/HermesExecutorFactory.h>
#else
#import <React/JSCExecutorFactory.h>
#endif

#import <React/RCTJSIExecutorRuntimeInstaller.h>
#import <ReactCommon/RCTTurboModuleManager.h>

#endif

RCT_EXTERN_C_BEGIN
Expand All @@ -38,7 +26,7 @@ RCT_EXTERN_C_END
#if RCT_NEW_ARCH_ENABLED
RCT_EXTERN id<RCTTurboModule> RCTAppSetupDefaultModuleFromClass(Class moduleClass);

std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutorFactory(
facebook::react::JSIExecutor::RuntimeInstaller RCTAppSetupDefaultJsRuntimeInstaller(
RCTBridge *bridge,
RCTTurboModuleManager *turboModuleManager);
#endif
23 changes: 9 additions & 14 deletions React/AppSetup/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void RCTAppSetupPrepareApp(UIApplication *application)
return [moduleClass new];
}

std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutorFactory(
facebook::react::JSIExecutor::RuntimeInstaller RCTAppSetupDefaultJsRuntimeInstaller(
RCTBridge *bridge,
RCTTurboModuleManager *turboModuleManager)
{
Expand All @@ -111,19 +111,14 @@ void RCTAppSetupPrepareApp(UIApplication *application)
}
#endif

#if RCT_USE_HERMES
return std::make_unique<facebook::react::HermesExecutorFactory>(
#else
return std::make_unique<facebook::react::JSCExecutorFactory>(
#endif
facebook::react::RCTJSIExecutorRuntimeInstaller([turboModuleManager, bridge](facebook::jsi::Runtime &runtime) {
if (!bridge || !turboModuleManager) {
return;
}
facebook::react::RuntimeExecutor syncRuntimeExecutor =
[&](std::function<void(facebook::jsi::Runtime & runtime_)> &&callback) { callback(runtime); };
[turboModuleManager installJSBindingWithRuntimeExecutor:syncRuntimeExecutor];
}));
return facebook::react::RCTJSIExecutorRuntimeInstaller([turboModuleManager, bridge](facebook::jsi::Runtime &runtime) {
if (!bridge || !turboModuleManager) {
return;
}
facebook::react::RuntimeExecutor syncRuntimeExecutor =
[&](std::function<void(facebook::jsi::Runtime & runtime_)> &&callback) { callback(runtime); };
[turboModuleManager installJSBindingWithRuntimeExecutor:syncRuntimeExecutor];
});
}

#endif
39 changes: 33 additions & 6 deletions template/ios/HelloWorld/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
#import "AppDelegate.h"

#import <React/RCTAppSetupUtils.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTJSIExecutorRuntimeInstaller.h>
#import <React/RCTRootView.h>

#import <React/RCTAppSetupUtils.h>
#ifndef RCT_USE_HERMES
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
#define RCT_USE_HERMES 1
#else
#define RCT_USE_HERMES 0
#endif
#endif

#if RCT_USE_HERMES
#import <reacthermes/HermesExecutorFactory.h>
#else
#import <React/JSCExecutorFactory.h>
#endif

#if RCT_NEW_ARCH_ENABLED
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
Expand All @@ -18,7 +32,7 @@

static NSString *const kRNConcurrentRoot = @"concurrentRoot";

@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
@interface AppDelegate () <RCTTurboModuleManagerDelegate> {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
Expand All @@ -27,6 +41,9 @@ @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate>
@end
#endif

@interface AppDelegate () <RCTCxxBridgeDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand Down Expand Up @@ -91,18 +108,28 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#endif
}

#if RCT_NEW_ARCH_ENABLED

#pragma mark - RCTCxxBridgeDelegate

- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
#if RCT_NEW_ARCH_ENABLED
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
auto installBindings = RCTAppSetupDefaultJsRuntimeInstaller(bridge, _turboModuleManager);
#else
auto installBindings = facebook::react::RCTJSIExecutorRuntimeInstaller(nullptr);
#endif

#if RCT_USE_HERMES
return std::make_unique<facebook::react::HermesExecutorFactory>(installBindings);
#else
return std::make_unique<facebook::react::JSCExecutorFactory>(installBindings);
#endif
}

#if RCT_NEW_ARCH_ENABLED

#pragma mark RCTTurboModuleManagerDelegate

- (Class)getModuleClassFromName:(const char *)name
Expand Down

0 comments on commit 78ab43b

Please sign in to comment.