diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index 03463c6c636..020b2faa110 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -1814,6 +1814,28 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNReanimated/worklets (3.17.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNReanimated/worklets/apple (= 3.17.0) + - Yoga + - RNReanimated/worklets/apple (3.17.0): - DoubleConversion - glog - hermes-engine @@ -2229,7 +2251,7 @@ SPEC CHECKSUMS: RNCPicker: b978067931744f5a7316b48b8dcf145d4d722672 RNFlashList: 6f169ad83e52579b7754cbbcec1b004c27d82c93 RNGestureHandler: fc5ce5bf284640d3af6431c3a5c3bc121e98d045 - RNReanimated: 2db902281618797873d75426f334ede4e503baf8 + RNReanimated: c03f9fdff5fd382d1833c37fa0e6f64ffd9b8a92 RNScreens: 2fe13c8d610ef2d9d5ace2e7d85b716ec0f5217c RNSVG: 536cd3c866c878faf72beaba166c8b02fe2b762b SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 diff --git a/apps/macos-example/macos/Podfile.lock b/apps/macos-example/macos/Podfile.lock index fd373c0963c..b7d1bdb07a2 100644 --- a/apps/macos-example/macos/Podfile.lock +++ b/apps/macos-example/macos/Podfile.lock @@ -1547,6 +1547,28 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNReanimated/worklets (3.17.0): + - DoubleConversion + - glog + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNReanimated/worklets/apple (= 3.17.0) + - Yoga + - RNReanimated/worklets/apple (3.17.0): - DoubleConversion - glog - RCT-Folly (= 2024.01.01.00) @@ -1843,7 +1865,7 @@ SPEC CHECKSUMS: RNCAsyncStorage: ec53e44dc3e75b44aa2a9f37618a49c3bc080a7a RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94 RNGestureHandler: 82f59e40580e0c2f8262552c149716511131b412 - RNReanimated: 8b9e602d3bc250cfd046c584454aa2a2efa8bd7e + RNReanimated: ed490424d3b8b9f2acd104577c73b374fc79310b RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d SocketRocket: 9ee265c4b5ae2382d18e4ee1d2dd2d7af0ff1ab5 Yoga: a7f65c1fd1394973b9ea40c9c270530e9d7cd2e7 diff --git a/apps/paper-example/ios/Podfile.lock b/apps/paper-example/ios/Podfile.lock index 64e1c430d9e..2f6d011a99d 100644 --- a/apps/paper-example/ios/Podfile.lock +++ b/apps/paper-example/ios/Podfile.lock @@ -1668,6 +1668,28 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNReanimated/worklets (3.17.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNReanimated/worklets/apple (= 3.17.0) + - Yoga + - RNReanimated/worklets/apple (3.17.0): - DoubleConversion - glog - hermes-engine @@ -2019,7 +2041,7 @@ SPEC CHECKSUMS: RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94 RNFlashList: 115dd44377580761bff386a0caebf165424cf16f RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8 - RNReanimated: 9ef3b1908a15b0b778edd6dacad9c71e7fe9e849 + RNReanimated: 1d16252a3b482d884ba83b09800594fbfa773291 RNScreens: de948b09c9a30f3ea52f9840dd6f8ce92b4e33d3 RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 diff --git a/apps/tvos-example/ios/Podfile.lock b/apps/tvos-example/ios/Podfile.lock index 832de32cefd..f6536db5edd 100644 --- a/apps/tvos-example/ios/Podfile.lock +++ b/apps/tvos-example/ios/Podfile.lock @@ -1575,6 +1575,28 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNReanimated/worklets (3.17.0): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - RNReanimated/worklets/apple (= 3.17.0) + - Yoga + - RNReanimated/worklets/apple (3.17.0): - DoubleConversion - glog - hermes-engine @@ -1864,7 +1886,7 @@ SPEC CHECKSUMS: React-utils: 3fce26d04c6776ddd47f255e7f3adc70d61b4491 ReactCodegen: 61cc9f25250fd53c91d30d82e84a1c6aafcf451a ReactCommon: b927fd46115bd2acb146e24cf1a08f22abda8b3f - RNReanimated: b007fe1002350dd2ffb10fec214560a167794e12 + RNReanimated: 3a5e1e235c940894097b0734aad9ebce45431ddd SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 Yoga: 651e5fd560c7e408ab9d9ca44b8de1b622d7f0cc diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp index a5a5ea214ee..404ca6b6493 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp @@ -52,12 +52,12 @@ using namespace facebook; namespace reanimated { NativeReanimatedModule::NativeReanimatedModule( + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime &rnRuntime, const std::shared_ptr &jsScheduler, const std::shared_ptr &jsQueue, const std::shared_ptr &uiScheduler, const PlatformDepMethodsHolder &platformDepMethodsHolder, - const std::string &valueUnpackerCode, const bool isBridgeless, const bool isReducedMotion) : NativeReanimatedModuleSpec( @@ -65,16 +65,17 @@ NativeReanimatedModule::NativeReanimatedModule( isBridgeless_(isBridgeless), isReducedMotion_(isReducedMotion), jsQueue_(jsQueue), + nativeWorkletsModule_(nativeWorkletsModule), jsScheduler_(jsScheduler), uiScheduler_(uiScheduler), + valueUnpackerCode_(nativeWorkletsModule->getValueUnpackerCode()), uiWorkletRuntime_(std::make_shared( rnRuntime, jsQueue, jsScheduler_, "Reanimated UI runtime", true /* supportsLocking */, - valueUnpackerCode)), - valueUnpackerCode_(valueUnpackerCode), + valueUnpackerCode_)), eventHandlerRegistry_(std::make_unique()), requestRender_(platformDepMethodsHolder.requestRender), onRenderCallback_([this](const double timestampMs) { diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h index e816214b340..41af8f2e0d9 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h @@ -13,6 +13,7 @@ #include #endif // RCT_NEW_ARCH_ENABLED +#include #include #include #include @@ -32,12 +33,12 @@ namespace reanimated { class NativeReanimatedModule : public NativeReanimatedModuleSpec { public: NativeReanimatedModule( + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime &rnRuntime, const std::shared_ptr &jsScheduler, const std::shared_ptr &jsQueue, const std::shared_ptr &uiScheduler, const PlatformDepMethodsHolder &platformDepMethodsHolder, - const std::string &valueUnpackerCode, const bool isBridgeless, const bool isReducedMotion); @@ -168,18 +169,23 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { return *layoutAnimationsManager_; } - inline jsi::Runtime &getUIRuntime() const { + [[nodiscard]] inline jsi::Runtime &getUIRuntime() const { return uiWorkletRuntime_->getJSIRuntime(); } - inline bool isBridgeless() const { + [[nodiscard]] inline bool isBridgeless() const { return isBridgeless_; } - inline bool isReducedMotion() const { + [[nodiscard]] inline bool isReducedMotion() const { return isReducedMotion_; } + [[nodiscard]] inline std::shared_ptr + getNativeWorkletsModule() const { + return nativeWorkletsModule_; + } + private: void commonInit(const PlatformDepMethodsHolder &platformDepMethodsHolder); @@ -195,10 +201,11 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { const bool isBridgeless_; const bool isReducedMotion_; const std::shared_ptr jsQueue_; + const std::shared_ptr nativeWorkletsModule_; const std::shared_ptr jsScheduler_; const std::shared_ptr uiScheduler_; + const std::string valueUnpackerCode_; std::shared_ptr uiWorkletRuntime_; - std::string valueUnpackerCode_; std::unique_ptr eventHandlerRegistry_; const RequestRenderFunction requestRender_; diff --git a/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.cpp b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.cpp new file mode 100644 index 00000000000..1a776bf8812 --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.cpp @@ -0,0 +1,25 @@ +#include + +#ifdef RCT_NEW_ARCH_ENABLED +#include +#include +#endif // RCT_NEW_ARCH_ENABLED + +#include + +#ifdef __ANDROID__ +#include +#endif // __ANDROID__ + +#include + +using namespace facebook; + +namespace worklets { + +NativeWorkletsModule::NativeWorkletsModule(const std::string &valueUnpackerCode) + : NativeWorkletsModuleSpec(nullptr), + valueUnpackerCode_(valueUnpackerCode) {} + +NativeWorkletsModule::~NativeWorkletsModule() {} +} // namespace worklets diff --git a/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.h b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.h new file mode 100644 index 00000000000..15e8d7a271a --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include + +namespace worklets { + +class NativeWorkletsModule : public NativeWorkletsModuleSpec { + public: + explicit NativeWorkletsModule(const std::string &valueUnpackerCode); + + ~NativeWorkletsModule(); + + [[nodiscard]] inline std::string getValueUnpackerCode() const { + return valueUnpackerCode_; + } + + private: + const std::string valueUnpackerCode_; +}; + +} // namespace worklets diff --git a/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.cpp b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.cpp new file mode 100644 index 00000000000..d8828c7fc31 --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.cpp @@ -0,0 +1,9 @@ +#include + +namespace worklets { + +NativeWorkletsModuleSpec::NativeWorkletsModuleSpec( + const std::shared_ptr jsInvoker) + : TurboModule("NativeWorklets", jsInvoker) {} + +} // namespace worklets diff --git a/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.h b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.h new file mode 100644 index 00000000000..5b813ceaf0e --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +using namespace facebook; +using namespace react; + +namespace worklets { + +class JSI_EXPORT NativeWorkletsModuleSpec : public TurboModule { + protected: + explicit NativeWorkletsModuleSpec( + const std::shared_ptr jsInvoker); +}; + +} // namespace worklets diff --git a/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp new file mode 100644 index 00000000000..37565314534 --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp @@ -0,0 +1,14 @@ +#include + +namespace worklets { + +void RNRuntimeWorkletDecorator::decorate( + jsi::Runtime &rnRuntime, + const std::shared_ptr &nativeWorkletsModule) { + rnRuntime.global().setProperty( + rnRuntime, + "__workletsModuleProxy", + jsi::Object::createFromHostObject(rnRuntime, nativeWorkletsModule)); +} + +} // namespace worklets diff --git a/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h new file mode 100644 index 00000000000..9884e71091a --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +using namespace facebook; + +namespace worklets { + +class RNRuntimeWorkletDecorator { + // TODO: Rename to `RNRuntimeWorkletsDecorator` or something more suitable. + public: + static void decorate( + jsi::Runtime &rnRuntime, + const std::shared_ptr &nativeWorkletsModule); +}; + +} // namespace worklets diff --git a/packages/react-native-reanimated/RNReanimated.podspec b/packages/react-native-reanimated/RNReanimated.podspec index d27eaf85978..856666f6bd4 100644 --- a/packages/react-native-reanimated/RNReanimated.podspec +++ b/packages/react-native-reanimated/RNReanimated.podspec @@ -78,6 +78,21 @@ Pod::Spec.new do |s| s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14", :visionos => "1.0" } s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" } + s.subspec "worklets" do |ss| + ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}" + ss.header_dir = "worklets" + ss.header_mappings_dir = "Common/cpp/worklets" + + ss.subspec "apple" do |sss| + # Please be careful with the snakes. + # 🐍🐍🐍 + # Thank you for your understanding. + sss.source_files = "apple/worklets/**/*.{mm,h,m}" + sss.header_dir = "worklets" + sss.header_mappings_dir = "apple/worklets" + end + end + s.subspec "reanimated" do |ss| ss.source_files = "Common/cpp/reanimated/**/*.{cpp,h}" ss.header_dir = "reanimated" @@ -90,12 +105,6 @@ Pod::Spec.new do |s| end end - s.subspec "worklets" do |ss| - ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}" - ss.header_dir = "worklets" - ss.header_mappings_dir = "Common/cpp/worklets" - end - gcc_debug_definitions = "$(inherited)" if !is_release gcc_debug_definitions << " HERMES_ENABLE_DEBUGGER=1" diff --git a/packages/react-native-reanimated/android/build.gradle b/packages/react-native-reanimated/android/build.gradle index 3afaa62ff11..a35ae1fcdf7 100644 --- a/packages/react-native-reanimated/android/build.gradle +++ b/packages/react-native-reanimated/android/build.gradle @@ -461,8 +461,8 @@ task createNativeDepsDirectories() { task packageNdkLibs(type: Copy) { from("$buildDir/reanimated-ndk/all") - include("**/libreanimated.so") include("**/libworklets.so") + include("**/libreanimated.so") into("$projectDir/src/main/jniLibs") } diff --git a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp index e8573872bcc..42b1f21ce14 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp +++ b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp @@ -29,25 +29,27 @@ using namespace react; NativeProxy::NativeProxy( jni::alias_ref jThis, + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime *rnRuntime, const std::shared_ptr &jsCallInvoker, const std::shared_ptr &uiScheduler, jni::global_ref layoutAnimations, - jni::alias_ref messageQueueThread, + jni::alias_ref messageQueueThread #ifdef RCT_NEW_ARCH_ENABLED + , jni::alias_ref - fabricUIManager, + fabricUIManager #endif - const std::string &valueUnpackerCode) + ) : javaPart_(jni::make_global(jThis)), rnRuntime_(rnRuntime), nativeReanimatedModule_(std::make_shared( + nativeWorkletsModule, *rnRuntime, std::make_shared(*rnRuntime, jsCallInvoker), std::make_shared(messageQueueThread), uiScheduler, getPlatformDependentMethods(), - valueUnpackerCode, /* isBridgeless */ false, getIsReducedMotion())), layoutAnimations_(std::move(layoutAnimations)) { @@ -59,23 +61,23 @@ NativeProxy::NativeProxy( #ifdef RCT_NEW_ARCH_ENABLED NativeProxy::NativeProxy( jni::alias_ref jThis, + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime *rnRuntime, RuntimeExecutor runtimeExecutor, const std::shared_ptr &uiScheduler, jni::global_ref layoutAnimations, jni::alias_ref messageQueueThread, jni::alias_ref - fabricUIManager, - const std::string &valueUnpackerCode) + fabricUIManager) : javaPart_(jni::make_global(jThis)), rnRuntime_(rnRuntime), nativeReanimatedModule_(std::make_shared( + nativeWorkletsModule, *rnRuntime, std::make_shared(*rnRuntime, runtimeExecutor), std::make_shared(messageQueueThread), uiScheduler, getPlatformDependentMethods(), - valueUnpackerCode, /* isBridgeless */ true, getIsReducedMotion())), layoutAnimations_(std::move(layoutAnimations)) { @@ -112,54 +114,62 @@ NativeProxy::~NativeProxy() { jni::local_ref NativeProxy::initHybrid( jni::alias_ref jThis, + jni::alias_ref jWorkletsModule, jlong jsContext, jni::alias_ref jsCallInvokerHolder, jni::alias_ref androidUiScheduler, jni::alias_ref layoutAnimations, - jni::alias_ref messageQueueThread, + jni::alias_ref messageQueueThread #ifdef RCT_NEW_ARCH_ENABLED + , jni::alias_ref - fabricUIManager, + fabricUIManager #endif - const std::string &valueUnpackerCode) { +) { auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); auto uiScheduler = androidUiScheduler->cthis()->getUIScheduler(); + auto nativeWorkletsModule = + jWorkletsModule->cthis()->getNativeWorkletsModule(); return makeCxxInstance( jThis, + nativeWorkletsModule, (jsi::Runtime *)jsContext, jsCallInvoker, uiScheduler, make_global(layoutAnimations), - messageQueueThread, + messageQueueThread #ifdef RCT_NEW_ARCH_ENABLED - fabricUIManager, + , + fabricUIManager #endif - valueUnpackerCode); + ); } #ifdef RCT_NEW_ARCH_ENABLED jni::local_ref NativeProxy::initHybridBridgeless( jni::alias_ref jThis, + jni::alias_ref jWorkletsModule, jlong jsContext, jni::alias_ref runtimeExecutorHolder, jni::alias_ref androidUiScheduler, jni::alias_ref layoutAnimations, jni::alias_ref messageQueueThread, jni::alias_ref - fabricUIManager, - const std::string &valueUnpackerCode) { + fabricUIManager) { auto uiScheduler = androidUiScheduler->cthis()->getUIScheduler(); auto runtimeExecutor = runtimeExecutorHolder->cthis()->get(); + auto nativeWorkletsModule = + jWorkletsModule->cthis()->getNativeWorkletsModule(); return makeCxxInstance( jThis, + nativeWorkletsModule, (jsi::Runtime *)jsContext, runtimeExecutor, uiScheduler, make_global(layoutAnimations), messageQueueThread, - fabricUIManager, - valueUnpackerCode); + fabricUIManager); } #endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.h b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.h index 3f5e46a6bc8..1f2ac757987 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.h +++ b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -149,29 +150,31 @@ class NativeProxy : public jni::HybridClass { "Lcom/swmansion/reanimated/NativeProxy;"; static jni::local_ref initHybrid( jni::alias_ref jThis, + jni::alias_ref jWorkletsModule, jlong jsContext, jni::alias_ref jsCallInvokerHolder, jni::alias_ref androidUiScheduler, jni::alias_ref layoutAnimations, - jni::alias_ref messageQueueThread, + jni::alias_ref messageQueueThread #ifdef RCT_NEW_ARCH_ENABLED + , jni::alias_ref - fabricUIManager, + fabricUIManager #endif - const std::string &valueUnpackerCode); + ); #ifdef RCT_NEW_ARCH_ENABLED static jni::local_ref initHybridBridgeless( jni::alias_ref jThis, + jni::alias_ref jWorkletsModule, jlong jsContext, jni::alias_ref runtimeExecutorHolder, jni::alias_ref androidUiScheduler, jni::alias_ref layoutAnimations, jni::alias_ref messageQueueThread, jni::alias_ref - fabricUIManager, - const std::string &valueUnpackerCode); + fabricUIManager); #endif // RCT_NEW_ARCH_ENABLED static void registerNatives(); @@ -275,28 +278,30 @@ class NativeProxy : public jni::HybridClass { explicit NativeProxy( jni::alias_ref jThis, + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime *rnRuntime, const std::shared_ptr &jsCallInvoker, const std::shared_ptr &uiScheduler, jni::global_ref layoutAnimations, - jni::alias_ref messageQueueThread, + jni::alias_ref messageQueueThread #ifdef RCT_NEW_ARCH_ENABLED + , jni::alias_ref - fabricUIManager, + fabricUIManager #endif - const std::string &valueUnpackerCode); + ); #ifdef RCT_NEW_ARCH_ENABLED explicit NativeProxy( jni::alias_ref jThis, + const std::shared_ptr &nativeWorkletsModule, jsi::Runtime *rnRuntime, RuntimeExecutor runtimeExecutor, const std::shared_ptr &uiScheduler, jni::global_ref layoutAnimations, jni::alias_ref messageQueueThread, jni::alias_ref - fabricUIManager, - const std::string &valueUnpackerCode); + fabricUIManager); void commonInit(jni::alias_ref &fabricUIManager); diff --git a/packages/react-native-reanimated/android/src/main/cpp/worklets/CMakeLists.txt b/packages/react-native-reanimated/android/src/main/cpp/worklets/CMakeLists.txt index 8961bf3d8f1..26edc5003d3 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/worklets/CMakeLists.txt +++ b/packages/react-native-reanimated/android/src/main/cpp/worklets/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.8) file(GLOB_RECURSE WORKLETS_COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/worklets/*.cpp") +file(GLOB_RECURSE WORKLETS_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/worklets/*.cpp") # Consume shared libraries and headers from prefabs find_package(fbjni REQUIRED CONFIG) @@ -14,6 +15,7 @@ add_library( worklets SHARED ${WORKLETS_COMMON_CPP_SOURCES} + ${WORKLETS_ANDROID_CPP_SOURCES} ) # includes @@ -21,12 +23,15 @@ target_include_directories( worklets PUBLIC "${COMMON_CPP_DIR}" + "${ANDROID_CPP_DIR}" ) target_include_directories( worklets PRIVATE "${REACT_NATIVE_DIR}/ReactCommon" + "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule" + "${REACT_NATIVE_DIR}/ReactCommon/react/nativemodule/core/ReactCommon" "${REACT_NATIVE_DIR}/ReactCommon/callinvoker" "${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor" ) @@ -74,6 +79,7 @@ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) else() target_link_libraries( worklets + ReactAndroid::react_nativemodule_core ReactAndroid::folly_runtime ReactAndroid::glog ReactAndroid::reactnativejni diff --git a/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.cpp b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.cpp new file mode 100644 index 00000000000..6be7b73349d --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include +#ifdef RCT_NEW_ARCH_ENABLED +#include +#endif + +#include +#include + +namespace worklets { + +using namespace facebook; +using namespace react; + +WorkletsModule::WorkletsModule( + jni::alias_ref jThis, + jsi::Runtime *rnRuntime, + const std::string &valueUnpackerCode) + : javaPart_(jni::make_global(jThis)), + rnRuntime_(rnRuntime), + nativeWorkletsModule_( + std::make_shared(valueUnpackerCode)) { + RNRuntimeWorkletDecorator::decorate(*rnRuntime_, nativeWorkletsModule_); +} + +jni::local_ref WorkletsModule::initHybrid( + jni::alias_ref jThis, + jlong jsContext, + const std::string &valueUnpackerCode) { + return makeCxxInstance(jThis, (jsi::Runtime *)jsContext, valueUnpackerCode); +} + +void WorkletsModule::registerNatives() { + registerHybrid({makeNativeMethod("initHybrid", WorkletsModule::initHybrid)}); +} + +} // namespace worklets diff --git a/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.h b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.h new file mode 100644 index 00000000000..349853b1edb --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsModule.h @@ -0,0 +1,54 @@ +#pragma once + +#ifdef RCT_NEW_ARCH_ENABLED +#include +#include +#include +#endif // RCT_NEW_ARCH_ENABLED + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace worklets { + +using namespace facebook; +using namespace facebook::jni; + +class WorkletsModule : public jni::HybridClass { + public: + static auto constexpr kJavaDescriptor = + "Lcom/swmansion/worklets/WorkletsModule;"; + + static jni::local_ref initHybrid( + jni::alias_ref jThis, + jlong jsContext, + const std::string &valueUnpackerCode); + + static void registerNatives(); + + inline std::shared_ptr getNativeWorkletsModule() { + return nativeWorkletsModule_; + } + + private: + friend HybridBase; + jni::global_ref javaPart_; + jsi::Runtime *rnRuntime_; + std::shared_ptr nativeWorkletsModule_; + + explicit WorkletsModule( + jni::alias_ref jThis, + jsi::Runtime *rnRuntime, + const std::string &valueUnpackerCode); +}; + +} // namespace worklets diff --git a/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp new file mode 100644 index 00000000000..3c35b26e36a --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp @@ -0,0 +1,8 @@ +#include + +#include + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { + return facebook::jni::initialize( + vm, [] { worklets::WorkletsModule::registerNatives(); }); +} diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java index f38057565bc..9ca28144b94 100644 --- a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java @@ -34,6 +34,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter; import com.swmansion.reanimated.layoutReanimation.AnimationsManager; import com.swmansion.reanimated.nativeProxy.NoopEventHandler; +import com.swmansion.worklets.WorkletsModule; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; @@ -93,6 +94,7 @@ public interface OnAnimationFrame { void onAnimationFrame(double timestampMs); } + private final WorkletsModule mWorkletsModule; private final AnimationsManager mAnimationManager; private final UIImplementation mUIImplementation; private final DeviceEventManagerModule.RCTDeviceEventEmitter mEventEmitter; @@ -131,9 +133,8 @@ public void invalidate() { } } - public void initWithContext( - ReactApplicationContext reactApplicationContext, String valueUnpackerCode) { - mNativeProxy = new NativeProxy(reactApplicationContext, valueUnpackerCode); + public void initWithContext(ReactApplicationContext reactApplicationContext) { + mNativeProxy = new NativeProxy(reactApplicationContext, mWorkletsModule); mAnimationManager.setAndroidUIScheduler(getNativeProxy().getAndroidUIScheduler()); compatibility = new ReaCompatibility(reactApplicationContext); compatibility.registerFabricEventListener(this); @@ -152,8 +153,9 @@ public NativeUpdateOperation(int viewTag, WritableMap nativeProps) { private Queue mOperationsInBatch = new LinkedList<>(); private boolean mTryRunBatchUpdatesSynchronously = false; - public NodesManager(ReactContext context) { + public NodesManager(ReactContext context, WorkletsModule workletsModule) { mContext = context; + mWorkletsModule = workletsModule; int uiManagerType = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED ? UIManagerType.FABRIC : UIManagerType.DEFAULT; mUIManager = UIManagerHelper.getUIManager(context, uiManagerType); diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java index 43c77444651..8f32f0e6ec5 100644 --- a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java @@ -19,33 +19,40 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewManager; import com.facebook.systrace.Systrace; +import com.swmansion.worklets.WorkletsModule; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +// `WorkletsModule` should be included from a separate Java package, called `WorkletsPackage`. +// However, it's not possible with the current state of the Gradle Tools provided by +// RNC CLI - all packages besides the first found are ignored. +// Therefore, until we extract `react-native-worklets` to a separate package, +// we will host this module in Reanimated's package. @ReactModuleList( nativeModules = { + WorkletsModule.class, ReanimatedModule.class, ReanimatedUIManager.class, }) public class ReanimatedPackage extends TurboReactPackage implements ReactPackage { @Override - public NativeModule getModule(String name, @NonNull ReactApplicationContext reactContext) { - if (name.equals(ReanimatedModule.NAME)) { - return new ReanimatedModule(reactContext); - } - if (name.equals(ReanimatedUIManager.NAME)) { - return createUIManager(reactContext); - } - return null; + public NativeModule getModule( + @NonNull String name, @NonNull ReactApplicationContext reactContext) { + return switch (name) { + case WorkletsModule.NAME -> new WorkletsModule(reactContext); + case ReanimatedModule.NAME -> new ReanimatedModule(reactContext); + case ReanimatedUIManager.NAME -> createUIManager(reactContext); + default -> null; + }; } @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { Class[] moduleList = new Class[] { - ReanimatedModule.class, ReanimatedUIManager.class, + WorkletsModule.class, ReanimatedModule.class, ReanimatedUIManager.class, }; final Map reactModuleInfoMap = new HashMap<>(); diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java index 5956905b378..741e096f6e0 100644 --- a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java @@ -26,6 +26,7 @@ import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; import com.swmansion.reanimated.sensor.ReanimatedSensorContainer; import com.swmansion.reanimated.sensor.ReanimatedSensorType; +import com.swmansion.worklets.WorkletsModule; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashSet; @@ -38,6 +39,7 @@ public abstract class NativeProxyCommon { SoLoader.loadLibrary("reanimated"); } + protected final WorkletsModule mWorkletsModule; protected NodesManager mNodesManager; protected final WeakReference mContext; protected final AndroidUIScheduler mAndroidUIScheduler; @@ -50,6 +52,8 @@ public abstract class NativeProxyCommon { protected String cppVersion = null; protected NativeProxyCommon(ReactApplicationContext context) { + mWorkletsModule = + Objects.requireNonNull(context.getNativeModule(ReanimatedModule.class)).getWorkletsModule(); mAndroidUIScheduler = new AndroidUIScheduler(context); mContext = new WeakReference<>(context); reanimatedSensorContainer = new ReanimatedSensorContainer(mContext); diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/worklets/WorkletsModule.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/worklets/WorkletsModule.java new file mode 100644 index 00000000000..2da67792f66 --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/worklets/WorkletsModule.java @@ -0,0 +1,51 @@ +package com.swmansion.worklets; + +import androidx.annotation.OptIn; +import com.facebook.jni.HybridData; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.common.annotations.FrameworkAPI; +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.soloader.SoLoader; +import com.swmansion.reanimated.NativeWorkletsModuleSpec; +import java.util.Objects; + +@ReactModule(name = WorkletsModule.NAME) +public class WorkletsModule extends NativeWorkletsModuleSpec { + static { + SoLoader.loadLibrary("worklets"); + } + + @DoNotStrip + @SuppressWarnings("unused") + private HybridData mHybridData; + + /** + * @noinspection unused + */ + protected HybridData getHybridData() { + return mHybridData; + } + + /** + * @noinspection JavaJniMissingFunction + */ + @OptIn(markerClass = FrameworkAPI.class) + private native HybridData initHybrid(long jsContext, String valueUnpackerCode); + + public WorkletsModule(ReactApplicationContext reactContext) { + super(reactContext); + } + + @OptIn(markerClass = FrameworkAPI.class) + @ReactMethod(isBlockingSynchronousMethod = true) + public boolean installTurboModule(String valueUnpackerCode) { + var context = getReactApplicationContext(); + var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get(); + + mHybridData = initHybrid(jsContext, valueUnpackerCode); + + return true; + } +} diff --git a/packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java b/packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java index 4560b0979d4..e7f328621cd 100644 --- a/packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java +++ b/packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java @@ -34,5 +34,5 @@ public NativeReanimatedModuleSpec(ReactApplicationContext reactContext) { @ReactMethod(isBlockingSynchronousMethod = true) @DoNotStrip - public abstract boolean installTurboModule(String valueUnpackerCode); + public abstract boolean installTurboModule(); } diff --git a/packages/react-native-reanimated/android/src/paper/java/com/swmansion/worklets/NativeWorkletsModuleSpec.java b/packages/react-native-reanimated/android/src/paper/java/com/swmansion/worklets/NativeWorkletsModuleSpec.java new file mode 100644 index 00000000000..5d326dc771a --- /dev/null +++ b/packages/react-native-reanimated/android/src/paper/java/com/swmansion/worklets/NativeWorkletsModuleSpec.java @@ -0,0 +1,28 @@ +// This file should be a part of `worklets` package but codegen +// mangles namespaces for its Fabric counterpart. +package com.swmansion.reanimated; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.turbomodule.core.interfaces.TurboModule; +import javax.annotation.Nonnull; + +public abstract class NativeWorkletsModuleSpec extends ReactContextBaseJavaModule + implements TurboModule { + public static final String NAME = "WorkletsModule"; + + public NativeWorkletsModuleSpec(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public @Nonnull String getName() { + return NAME; + } + + @ReactMethod(isBlockingSynchronousMethod = true) + @DoNotStrip + public abstract boolean installTurboModule(String valueUnpackerCode); +} diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java index 177fc0fad91..1f732ab91f1 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java @@ -14,6 +14,7 @@ import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder; import com.swmansion.reanimated.nativeProxy.NativeProxyCommon; +import com.swmansion.worklets.WorkletsModule; import java.util.HashMap; import java.util.Objects; @@ -23,7 +24,7 @@ public class NativeProxy extends NativeProxyCommon { private final HybridData mHybridData; public @OptIn(markerClass = FrameworkAPI.class) NativeProxy( - ReactApplicationContext context, String valueUnpackerCode) { + ReactApplicationContext context, WorkletsModule workletsModule) { super(context); ReactFeatureFlagsWrapper.enableMountHooks(); @@ -38,25 +39,25 @@ public class NativeProxy extends NativeProxyCommon { RuntimeExecutor runtimeExecutor = context.getRuntimeExecutor(); mHybridData = initHybridBridgeless( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), runtimeExecutor, mAndroidUIScheduler, LayoutAnimations, messageQueueThread, - fabricUIManager, - valueUnpackerCode); + fabricUIManager); } else { CallInvokerHolderImpl callInvokerHolder = (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder(); mHybridData = initHybrid( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), callInvokerHolder, mAndroidUIScheduler, LayoutAnimations, messageQueueThread, - fabricUIManager, - valueUnpackerCode); + fabricUIManager); } prepareLayoutAnimations(LayoutAnimations); installJSIBindings(); @@ -66,22 +67,22 @@ public class NativeProxy extends NativeProxyCommon { } private native HybridData initHybrid( + WorkletsModule workletsModule, long jsContext, CallInvokerHolderImpl jsCallInvokerHolder, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, MessageQueueThread messageQueueThread, - FabricUIManager fabricUIManager, - String valueUnpackerCode); + FabricUIManager fabricUIManager); private native HybridData initHybridBridgeless( + WorkletsModule workletsModule, long jsContext, RuntimeExecutor runtimeExecutor, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, MessageQueueThread messageQueueThread, - FabricUIManager fabricUIManager, - String valueUnpackerCode); + FabricUIManager fabricUIManager); public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag); diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java index 66b8696331d..ddfb00aceb5 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java @@ -14,6 +14,7 @@ import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder; import com.swmansion.reanimated.nativeProxy.NativeProxyCommon; +import com.swmansion.worklets.WorkletsModule; import java.util.HashMap; import java.util.Objects; @@ -23,7 +24,7 @@ public class NativeProxy extends NativeProxyCommon { private final HybridData mHybridData; public @OptIn(markerClass = FrameworkAPI.class) NativeProxy( - ReactApplicationContext context, String valueUnpackerCode) { + ReactApplicationContext context, WorkletsModule workletsModule) { super(context); ReactFeatureFlagsWrapper.enableMountHooks(); @@ -38,25 +39,25 @@ public class NativeProxy extends NativeProxyCommon { RuntimeExecutor runtimeExecutor = context.getCatalystInstance().getRuntimeExecutor(); mHybridData = initHybridBridgeless( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), runtimeExecutor, mAndroidUIScheduler, LayoutAnimations, messageQueueThread, - fabricUIManager, - valueUnpackerCode); + fabricUIManager); } else { CallInvokerHolderImpl callInvokerHolder = (CallInvokerHolderImpl) context.getJSCallInvokerHolder(); mHybridData = initHybrid( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), callInvokerHolder, mAndroidUIScheduler, LayoutAnimations, messageQueueThread, - fabricUIManager, - valueUnpackerCode); + fabricUIManager); } prepareLayoutAnimations(LayoutAnimations); installJSIBindings(); @@ -66,22 +67,22 @@ public class NativeProxy extends NativeProxyCommon { } private native HybridData initHybrid( + WorkletsModule workletsModule, long jsContext, CallInvokerHolderImpl jsCallInvokerHolder, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, MessageQueueThread messageQueueThread, - FabricUIManager fabricUIManager, - String valueUnpackerCode); + FabricUIManager fabricUIManager); private native HybridData initHybridBridgeless( + WorkletsModule workletsModule, long jsContext, RuntimeExecutor runtimeExecutor, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, MessageQueueThread messageQueueThread, - FabricUIManager fabricUIManager, - String valueUnpackerCode); + FabricUIManager fabricUIManager); public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag); diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java index 01637b1b86a..9078f5486c6 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java @@ -12,6 +12,7 @@ import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder; import com.swmansion.reanimated.nativeProxy.NativeProxyCommon; +import com.swmansion.worklets.WorkletsModule; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Objects; @@ -22,7 +23,7 @@ public class NativeProxy extends NativeProxyCommon { private final HybridData mHybridData; @OptIn(markerClass = FrameworkAPI.class) - public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { + public NativeProxy(ReactApplicationContext context, WorkletsModule workletsModule) { super(context); CallInvokerHolderImpl holder = (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder(); @@ -30,12 +31,12 @@ public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread(); mHybridData = initHybrid( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), holder, mAndroidUIScheduler, LayoutAnimations, - messageQueueThread, - valueUnpackerCode); + messageQueueThread); prepareLayoutAnimations(LayoutAnimations); installJSIBindings(); if (BuildConfig.DEBUG) { @@ -45,12 +46,12 @@ public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { @OptIn(markerClass = FrameworkAPI.class) private native HybridData initHybrid( + WorkletsModule workletsModule, long jsContext, CallInvokerHolderImpl jsCallInvokerHolder, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, - MessageQueueThread messageQueueThread, - String valueUnpackerCode); + MessageQueueThread messageQueueThread); public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag); diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java index 171ef0fac80..f4bfa2c555c 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java @@ -12,6 +12,7 @@ import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder; import com.swmansion.reanimated.nativeProxy.NativeProxyCommon; +import com.swmansion.worklets.WorkletsModule; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Objects; @@ -22,19 +23,19 @@ public class NativeProxy extends NativeProxyCommon { private final HybridData mHybridData; @OptIn(markerClass = FrameworkAPI.class) - public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { + public NativeProxy(ReactApplicationContext context, WorkletsModule workletsModule) { super(context); CallInvokerHolderImpl holder = (CallInvokerHolderImpl) context.getJSCallInvokerHolder(); LayoutAnimations LayoutAnimations = new LayoutAnimations(context); ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread(); mHybridData = initHybrid( + workletsModule, Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), holder, mAndroidUIScheduler, LayoutAnimations, - messageQueueThread, - valueUnpackerCode); + messageQueueThread); prepareLayoutAnimations(LayoutAnimations); installJSIBindings(); if (BuildConfig.DEBUG) { @@ -44,12 +45,12 @@ public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { @OptIn(markerClass = FrameworkAPI.class) private native HybridData initHybrid( + WorkletsModule workletsModule, long jsContext, CallInvokerHolderImpl jsCallInvokerHolder, AndroidUIScheduler androidUIScheduler, LayoutAnimations LayoutAnimations, - MessageQueueThread messageQueueThread, - String valueUnpackerCode); + MessageQueueThread messageQueueThread); public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag); diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/74/com/swmansion/reanimated/ReanimatedModule.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/74/com/swmansion/reanimated/ReanimatedModule.java index 27e50a023f6..d8b23817c30 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/74/com/swmansion/reanimated/ReanimatedModule.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/74/com/swmansion/reanimated/ReanimatedModule.java @@ -11,6 +11,7 @@ import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModuleListener; +import com.swmansion.worklets.WorkletsModule; import java.util.ArrayList; import javax.annotation.Nullable; @@ -61,9 +62,15 @@ private interface UIThreadOperation { private ArrayList mOperations = new ArrayList<>(); private @Nullable NodesManager mNodesManager; + private final WorkletsModule mWorkletsModule; public ReanimatedModule(ReactApplicationContext reactContext) { super(reactContext); + mWorkletsModule = reactContext.getNativeModule(WorkletsModule.class); + } + + public WorkletsModule getWorkletsModule() { + return mWorkletsModule; } @Override @@ -129,20 +136,20 @@ public String getName() { /*package*/ public NodesManager getNodesManager() { if (mNodesManager == null) { - mNodesManager = new NodesManager(getReactApplicationContext()); + mNodesManager = new NodesManager(getReactApplicationContext(), mWorkletsModule); } return mNodesManager; } @ReactMethod(isBlockingSynchronousMethod = true) - public boolean installTurboModule(String valueUnpackerCode) { + public boolean installTurboModule() { // When debugging in chrome the JS context is not available. // https://github.com/facebook/react-native/blob/v0.67.0-rc.6/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobCollector.java#L25 Utils.isChromeDebugger = getReactApplicationContext().getJavaScriptContextHolder().get() == 0; if (!Utils.isChromeDebugger) { - this.getNodesManager().initWithContext(getReactApplicationContext(), valueUnpackerCode); + this.getNodesManager().initWithContext(getReactApplicationContext()); return true; } else { Log.w( diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedModule.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedModule.java index 460a13b284f..771bbbfd100 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedModule.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedModule.java @@ -11,6 +11,7 @@ import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.UIManagerModuleListener; +import com.swmansion.worklets.WorkletsModule; import java.util.ArrayList; import java.util.Objects; import javax.annotation.Nullable; @@ -61,9 +62,15 @@ private interface UIThreadOperation { private ArrayList mOperations = new ArrayList<>(); private @Nullable NodesManager mNodesManager; + private final WorkletsModule mWorkletsModule; public ReanimatedModule(ReactApplicationContext reactContext) { super(reactContext); + mWorkletsModule = reactContext.getNativeModule(WorkletsModule.class); + } + + public WorkletsModule getWorkletsModule() { + return mWorkletsModule; } @Override @@ -125,14 +132,14 @@ public void willDispatchViewUpdates(final UIManagerModule uiManager) { /*package*/ public NodesManager getNodesManager() { if (mNodesManager == null) { - mNodesManager = new NodesManager(getReactApplicationContext()); + mNodesManager = new NodesManager(getReactApplicationContext(), mWorkletsModule); } return mNodesManager; } @ReactMethod(isBlockingSynchronousMethod = true) - public boolean installTurboModule(String valueUnpackerCode) { + public boolean installTurboModule() { // When debugging in chrome the JS context is not available. // https://github.com/facebook/react-native/blob/v0.67.0-rc.6/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobCollector.java#L25 Utils.isChromeDebugger = @@ -140,7 +147,7 @@ public boolean installTurboModule(String valueUnpackerCode) { == 0; if (!Utils.isChromeDebugger) { - this.getNodesManager().initWithContext(getReactApplicationContext(), valueUnpackerCode); + this.getNodesManager().initWithContext(getReactApplicationContext()); return true; } else { Log.w( diff --git a/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm b/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm index c54cd5dfeb2..625c5c6e5a4 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm +++ b/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm @@ -23,6 +23,7 @@ #import #import #import +#import #if __has_include() #import @@ -275,8 +276,9 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body } } -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule : (nonnull NSString *)valueUnpackerCode) +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule) { + WorkletsModule *workletsModule = [_moduleRegistry moduleForName:"WorkletsModule"]; if (_isBridgeless) { #ifdef RCT_NEW_ARCH_ENABLED RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge; @@ -290,7 +292,7 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body }]; }); auto nativeReanimatedModule = reanimated::createReanimatedModuleBridgeless( - _moduleRegistry, rnRuntime, std::string([valueUnpackerCode UTF8String]), executorFunction); + self, _moduleRegistry, rnRuntime, workletsModule, executorFunction); [self attachReactEventListener]; [self commonInit:nativeReanimatedModule withRnRuntime:rnRuntime]; #else @@ -302,8 +304,8 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body : nullptr; if (jsiRuntime) { - auto nativeReanimatedModule = reanimated::createReanimatedModule( - self, self.bridge, self.bridge.jsCallInvoker, std::string([valueUnpackerCode UTF8String])); + auto nativeReanimatedModule = + reanimated::createReanimatedModule(self, self.bridge, self.bridge.jsCallInvoker, workletsModule); jsi::Runtime &rnRuntime = *jsiRuntime; [self commonInit:nativeReanimatedModule withRnRuntime:rnRuntime]; diff --git a/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.h b/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.h index 4101aa6157a..7e68aa16cd6 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.h +++ b/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.h @@ -7,6 +7,7 @@ #import #import #import +#import #import namespace reanimated { @@ -17,14 +18,15 @@ std::shared_ptr createReanimatedModule( REAModule *reaModule, RCTBridge *bridge, const std::shared_ptr &jsInvoker, - const std::string &valueUnpackerCode); + WorkletsModule *workletsModule); #ifdef RCT_NEW_ARCH_ENABLED std::shared_ptr createReanimatedModuleBridgeless( + REAModule *reaModule, RCTModuleRegistry *moduleRegistry, jsi::Runtime &runtime, - const std::string &valueUnpackerCode, + WorkletsModule *workletsModule, RuntimeExecutor runtimeExecutor); #endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.mm b/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.mm index b43cf359566..b960c6c642b 100644 --- a/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.mm +++ b/packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.mm @@ -59,7 +59,7 @@ static inline bool getIsReducedMotion() REAModule *reaModule, RCTBridge *bridge, const std::shared_ptr &jsInvoker, - const std::string &valueUnpackerCode) + WorkletsModule *workletsModule) { auto nodesManager = reaModule.nodesManager; @@ -75,13 +75,15 @@ static inline bool getIsReducedMotion() std::shared_ptr jsScheduler = std::make_shared(rnRuntime, jsInvoker); constexpr auto isBridgeless = false; + const auto nativeWorkletsModule = [workletsModule getNativeWorkletsModule]; + auto nativeReanimatedModule = std::make_shared( + nativeWorkletsModule, rnRuntime, jsScheduler, jsQueue, uiScheduler, platformDepMethodsHolder, - valueUnpackerCode, isBridgeless, getIsReducedMotion()); @@ -100,13 +102,12 @@ static inline bool getIsReducedMotion() #ifdef RCT_NEW_ARCH_ENABLED std::shared_ptr createReanimatedModuleBridgeless( + REAModule *reaModule, RCTModuleRegistry *moduleRegistry, jsi::Runtime &runtime, - const std::string &valueUnpackerCode, + WorkletsModule *workletsModule, RuntimeExecutor runtimeExecutor) { - REAModule *reaModule = [moduleRegistry moduleForName:"ReanimatedModule"]; - auto nodesManager = reaModule.nodesManager; auto jsQueue = std::make_shared([NSRunLoop currentRunLoop], ^(NSError *error) { @@ -116,17 +117,18 @@ static inline bool getIsReducedMotion() PlatformDepMethodsHolder platformDepMethodsHolder = makePlatformDepMethodsHolderBridgeless(moduleRegistry, nodesManager, reaModule); + const auto nativeWorkletsModule = [workletsModule getNativeWorkletsModule]; auto uiScheduler = std::make_shared(); auto jsScheduler = std::make_shared(runtime, runtimeExecutor); constexpr auto isBridgeless = true; auto nativeReanimatedModule = std::make_shared( + nativeWorkletsModule, runtime, jsScheduler, jsQueue, uiScheduler, platformDepMethodsHolder, - valueUnpackerCode, isBridgeless, getIsReducedMotion()); diff --git a/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.h b/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.h new file mode 100644 index 00000000000..25b96da8b9b --- /dev/null +++ b/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.h @@ -0,0 +1,9 @@ +#import +#import +#import + +@interface WorkletsModule : RCTEventEmitter + +- (std::shared_ptr)getNativeWorkletsModule; + +@end diff --git a/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.mm b/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.mm new file mode 100644 index 00000000000..78b1759f5c9 --- /dev/null +++ b/packages/react-native-reanimated/apple/worklets/apple/WorkletsModule.mm @@ -0,0 +1,40 @@ +#import +#import +#import + +using worklets::NativeWorkletsModule; +using worklets::RNRuntimeWorkletDecorator; + +@interface RCTBridge (JSIRuntime) +- (void *)runtime; +@end + +@interface RCTBridge (RCTTurboModule) +- (std::shared_ptr)jsCallInvoker; +- (void)_tryAndHandleError:(dispatch_block_t)block; +@end + +@implementation WorkletsModule { + std::shared_ptr nativeWorkletsModule_; +} + +- (std::shared_ptr)getNativeWorkletsModule +{ + return nativeWorkletsModule_; +} + +@synthesize moduleRegistry = _moduleRegistry; + +RCT_EXPORT_MODULE(WorkletsModule); + +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule : (nonnull NSString *)valueUnpackerCode) +{ + auto *bridge = self.bridge; + auto &rnRuntime = *(jsi::Runtime *)bridge.runtime; + nativeWorkletsModule_ = std::make_shared(std::string([valueUnpackerCode UTF8String])); + RNRuntimeWorkletDecorator::decorate(rnRuntime, nativeWorkletsModule_); + + return @YES; +} + +@end diff --git a/packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.ts b/packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.ts index 5c8eb576d50..51e084c9d79 100644 --- a/packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.ts +++ b/packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.ts @@ -10,7 +10,6 @@ import type { import { checkCppVersion } from '../platform-specific/checkCppVersion'; import { jsVersion } from '../platform-specific/jsVersion'; import type { WorkletRuntime } from '../runtimes'; -import { getValueUnpackerCode } from '../valueUnpacker'; import { isFabric } from '../PlatformChecker'; import type React from 'react'; import { getShadowNodeWrapperFromRef } from '../fabricUtils'; @@ -51,7 +50,7 @@ class NativeReanimatedModule implements IReanimatedModule { } global._REANIMATED_VERSION_JS = jsVersion; if (global.__reanimatedModuleProxy === undefined) { - ReanimatedTurboModule?.installTurboModule(getValueUnpackerCode()); + ReanimatedTurboModule?.installTurboModule(); } if (global.__reanimatedModuleProxy === undefined) { throw new ReanimatedError( diff --git a/packages/react-native-reanimated/src/privateGlobals.d.ts b/packages/react-native-reanimated/src/privateGlobals.d.ts index 6b201f4300a..932aed27f08 100644 --- a/packages/react-native-reanimated/src/privateGlobals.d.ts +++ b/packages/react-native-reanimated/src/privateGlobals.d.ts @@ -16,6 +16,7 @@ import type { import type { AnimatedStyle } from './helperTypes'; import type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI'; import type { ReanimatedModuleProxy } from './ReanimatedModule'; +import type { WorkletsModuleProxy } from './worklets'; import type { SensorContainer } from './SensorContainer'; import type { LayoutAnimationsManager } from './layoutReanimation/animationsManager'; import type { ProgressTransitionRegister } from './layoutReanimation/sharedTransitions'; @@ -30,6 +31,7 @@ declare global { var _IS_FABRIC: boolean | undefined; var _REANIMATED_VERSION_CPP: string | undefined; var _REANIMATED_VERSION_JS: string | undefined; + var __workletsModuleProxy: WorkletsModuleProxy | undefined; var __reanimatedModuleProxy: ReanimatedModuleProxy | undefined; var __callGuardDEV: typeof callGuardDEV | undefined; var evalWithSourceMap: diff --git a/packages/react-native-reanimated/src/specs/NativeReanimatedModule.ts b/packages/react-native-reanimated/src/specs/NativeReanimatedModule.ts index 2abef330632..3d4a836e9dd 100644 --- a/packages/react-native-reanimated/src/specs/NativeReanimatedModule.ts +++ b/packages/react-native-reanimated/src/specs/NativeReanimatedModule.ts @@ -3,7 +3,7 @@ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; interface Spec extends TurboModule { - installTurboModule: (valueUnpackerCode: string) => boolean; + installTurboModule: () => boolean; } export default TurboModuleRegistry.get('ReanimatedModule'); diff --git a/packages/react-native-reanimated/src/specs/NativeWorkletsModule.ts b/packages/react-native-reanimated/src/specs/NativeWorkletsModule.ts new file mode 100644 index 00000000000..21b42d70d3d --- /dev/null +++ b/packages/react-native-reanimated/src/specs/NativeWorkletsModule.ts @@ -0,0 +1,12 @@ +'use strict'; +import type { TurboModule } from 'react-native'; +import { TurboModuleRegistry } from 'react-native'; + +// This file would ideally be in `worklets/specs` but +// codegen is pretty stupid and stops looking after first `spec` directory found. + +interface Spec extends TurboModule { + installTurboModule: (valueUnpackerCode: string) => boolean; +} + +export default TurboModuleRegistry.get('WorkletsModule'); diff --git a/packages/react-native-reanimated/src/specs/index.ts b/packages/react-native-reanimated/src/specs/index.ts index 5d232a0b0b2..66b304030fa 100644 --- a/packages/react-native-reanimated/src/specs/index.ts +++ b/packages/react-native-reanimated/src/specs/index.ts @@ -1,4 +1,6 @@ 'use strict'; + +import WorkletsTurboModule from './NativeWorkletsModule'; import ReanimatedTurboModule from './NativeReanimatedModule'; -export { ReanimatedTurboModule }; +export { WorkletsTurboModule, ReanimatedTurboModule }; diff --git a/packages/react-native-reanimated/src/worklets/WorkletsModule/NativeWorklets.ts b/packages/react-native-reanimated/src/worklets/WorkletsModule/NativeWorklets.ts index b0d5675ebf8..2dbd69df4ab 100644 --- a/packages/react-native-reanimated/src/worklets/WorkletsModule/NativeWorklets.ts +++ b/packages/react-native-reanimated/src/worklets/WorkletsModule/NativeWorklets.ts @@ -1,9 +1,28 @@ 'use strict'; - +import { getValueUnpackerCode } from '../valueUnpacker'; +import { WorkletsTurboModule } from '../../specs'; +import { ReanimatedError } from '../../errors'; import type { IWorkletsModule } from '../../commonTypes'; +import type { WorkletsModuleProxy } from './workletsModuleProxy'; export function createNativeWorkletsModule(): IWorkletsModule { return new NativeWorklets(); } -class NativeWorklets {} +class NativeWorklets { + #workletsModuleProxy: WorkletsModuleProxy; + + constructor() { + if (global.__workletsModuleProxy === undefined) { + const valueUnpackerCode = getValueUnpackerCode(); + WorkletsTurboModule?.installTurboModule(valueUnpackerCode); + } + if (global.__workletsModuleProxy === undefined) { + throw new ReanimatedError( + `Native part of Reanimated doesn't seem to be initialized (Worklets). +See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#native-part-of-reanimated-doesnt-seem-to-be-initialized for more details.` + ); + } + this.#workletsModuleProxy = global.__workletsModuleProxy; + } +} diff --git a/packages/react-native-reanimated/src/worklets/WorkletsModule/index.ts b/packages/react-native-reanimated/src/worklets/WorkletsModule/index.ts index 76e617320c5..d72476a7c16 100644 --- a/packages/react-native-reanimated/src/worklets/WorkletsModule/index.ts +++ b/packages/react-native-reanimated/src/worklets/WorkletsModule/index.ts @@ -1,3 +1,4 @@ 'use strict'; export { WorkletsModule } from './workletsModuleInstance'; +export type { WorkletsModuleProxy } from './workletsModuleProxy'; diff --git a/packages/react-native-reanimated/src/worklets/WorkletsModule/workletsModuleProxy.ts b/packages/react-native-reanimated/src/worklets/WorkletsModule/workletsModuleProxy.ts new file mode 100644 index 00000000000..00ae1391e31 --- /dev/null +++ b/packages/react-native-reanimated/src/worklets/WorkletsModule/workletsModuleProxy.ts @@ -0,0 +1,4 @@ +'use strict'; + +/** Type of `__workletsModuleProxy` injected with JSI. */ +export interface WorkletsModuleProxy {} diff --git a/packages/react-native-reanimated/src/worklets/index.ts b/packages/react-native-reanimated/src/worklets/index.ts index 5d2e021f26a..54bac2152fd 100644 --- a/packages/react-native-reanimated/src/worklets/index.ts +++ b/packages/react-native-reanimated/src/worklets/index.ts @@ -1,3 +1,4 @@ 'use strict'; export { WorkletsModule } from './WorkletsModule'; +export type { WorkletsModuleProxy } from './WorkletsModule'; diff --git a/packages/react-native-reanimated/src/valueUnpacker.ts b/packages/react-native-reanimated/src/worklets/valueUnpacker.ts similarity index 96% rename from packages/react-native-reanimated/src/valueUnpacker.ts rename to packages/react-native-reanimated/src/worklets/valueUnpacker.ts index 8249a97a3a2..3945f3fb378 100644 --- a/packages/react-native-reanimated/src/valueUnpacker.ts +++ b/packages/react-native-reanimated/src/worklets/valueUnpacker.ts @@ -1,8 +1,8 @@ /* eslint-disable reanimated/use-reanimated-error */ 'use strict'; -import { shouldBeUseWeb } from './PlatformChecker'; -import { isWorkletFunction } from './commonTypes'; -import type { WorkletFunction } from './commonTypes'; +import { shouldBeUseWeb } from '../PlatformChecker'; +import { isWorkletFunction } from '../commonTypes'; +import type { WorkletFunction } from '../commonTypes'; function valueUnpacker( objectToUnpack: any,