Skip to content

Commit

Permalink
Use JSCallInvoker instead of RuntimeExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Jan 13, 2025
1 parent 8a18aff commit 687cc08
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifdef RCT_NEW_ARCH_ENABLED
#if REACT_NATIVE_MINOR_VERSION >= 77
#import <React/RCTCallInvokerModule.h>
#else
#import <React/RCTInitializing.h>
#if REACT_NATIVE_MINOR_VERSION >= 74
#import <React/RCTRuntimeExecutorModule.h>
#import <ReactCommon/RCTRuntimeExecutor.h>
#endif // REACT_NATIVE_MINOR_VERSION >= 74
#endif // REACT_NATIVE_MINOR_VERSION >= 77
#import <rnreanimated/rnreanimated.h>
#else // RCT_NEW_ARCH_ENABLED
#import <React/RCTBridgeModule.h>
Expand All @@ -20,10 +24,14 @@
@interface REAModule : RCTEventEmitter
#ifdef RCT_NEW_ARCH_ENABLED
<NativeReanimatedModuleSpec,
#if REACT_NATIVE_MINOR_VERSION >= 77
RCTCallInvokerModule,
#else
RCTInitializing,
#if REACT_NATIVE_MINOR_VERSION >= 74
RCTRuntimeExecutorModule,
#endif // REACT_NATIVE_MINOR_VERSION >= 74
#endif // REACT_NATIVE_MINOR_VERSION >= 77
#else
<RCTBridgeModule,
#endif // RCT_NEW_ARCH_ENABLED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#import <React/RCTBridge+Private.h>

#ifdef RCT_NEW_ARCH_ENABLED
#if REACT_NATIVE_MINOR_VERSION >= 77
#import <React/RCTCallInvoker.h>
#endif // REACT_NATIVE_MINOR_VERSION >= 77
#import <React/RCTFabricSurface.h>
#import <React/RCTScheduler.h>
#import <React/RCTSurface.h>
Expand Down Expand Up @@ -64,9 +67,11 @@ @implementation REAModule {
}

@synthesize moduleRegistry = _moduleRegistry;
#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
#if REACT_NATIVE_MINOR_VERSION >= 77 && defined(RCT_NEW_ARCH_ENABLED)
@synthesize callInvoker = _callInvoker;
#elif REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
@synthesize runtimeExecutor = _runtimeExecutor;
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
#endif

RCT_EXPORT_MODULE(ReanimatedModule);

Expand Down Expand Up @@ -285,6 +290,10 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body
#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
auto &rnRuntime = *(jsi::Runtime *)cxxBridge.runtime;
#if REACT_NATIVE_MINOR_VERSION >= 77
auto nativeReanimatedModule = reanimated::createReanimatedModuleBridgeless(
_moduleRegistry, rnRuntime, std::string([valueUnpackerCode UTF8String]), _callInvoker.callInvoker);
#else
auto executorFunction = ([executor = _runtimeExecutor](std::function<void(jsi::Runtime & runtime)> &&callback) {
// Convert to Objective-C block so it can be captured properly.
__block auto callbackBlock = callback;
Expand All @@ -295,6 +304,7 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body
});
auto nativeReanimatedModule = reanimated::createReanimatedModuleBridgeless(
_moduleRegistry, rnRuntime, std::string([valueUnpackerCode UTF8String]), executorFunction);
#endif
[self attachReactEventListener];
[self commonInit:nativeReanimatedModule withRnRuntime:rnRuntime];
#else // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ createReanimatedModuleBridgeless(
RCTModuleRegistry *moduleRegistry,
jsi::Runtime &runtime,
const std::string &valueUnpackerCode,
RuntimeExecutor runtimeExecutor);
#if REACT_NATIVE_MINOR_VERSION >= 77
const std::shared_ptr<facebook::react::CallInvoker> &callInvoker
#else
RuntimeExecutor runtimeExecutor
#endif
);
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)

void commonInit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ static inline bool getIsReducedMotion()
RCTModuleRegistry *moduleRegistry,
jsi::Runtime &runtime,
const std::string &valueUnpackerCode,
RuntimeExecutor runtimeExecutor)
#if REACT_NATIVE_MINOR_VERSION >= 77
const std::shared_ptr<facebook::react::CallInvoker> &callInvoker
#elif
RuntimeExecutor runtimeExecutor
#endif
)
{
REAModule *reaModule = [moduleRegistry moduleForName:"ReanimatedModule"];

Expand All @@ -117,7 +122,13 @@ static inline bool getIsReducedMotion()
makePlatformDepMethodsHolderBridgeless(moduleRegistry, nodesManager, reaModule);

auto uiScheduler = std::make_shared<REAIOSUIScheduler>();

#if REACT_NATIVE_MINOR_VERSION >= 77
auto jsScheduler = std::make_shared<JSScheduler>(runtime, callInvoker);
#else
auto jsScheduler = std::make_shared<JSScheduler>(runtime, runtimeExecutor);
#endif

constexpr auto isBridgeless = true;

auto nativeReanimatedModule = std::make_shared<NativeReanimatedModule>(
Expand Down

0 comments on commit 687cc08

Please sign in to comment.