From 6add48e9110baf6de6d737760663d9aa5d0482b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 21 Nov 2025 15:26:35 +0100 Subject: [PATCH] feat(Worklets): public RNWorklets headers --- apps/fabric-example/ios/Podfile.lock | 62 ++++++++++++++++++- apps/macos-example/macos/Podfile.lock | 52 +++++++++++++++- apps/tvos-example/ios/Podfile.lock | 60 +++++++++++++++++- .../docs/threading/scheduleOnRuntime.mdx | 2 +- .../AnimatedSensor/AnimatedSensorModule.h | 4 +- .../LayoutAnimationsManager.h | 2 +- .../NativeModules/ReanimatedModuleProxy.cpp | 2 +- .../android/CMakeLists.txt | 3 +- .../worklets/{Public => RunLoop}/AsyncQueue.h | 5 +- .../cpp/worklets/RunLoop/AsyncQueueImpl.h | 2 +- .../Common/cpp/worklets/RunLoop/EventLoop.h | 2 +- .../cpp/worklets/SharedItems/Serializable.h | 5 +- .../cpp/worklets/SharedItems/Synchronizable.h | 5 +- .../worklets/WorkletRuntime/WorkletRuntime.h | 7 ++- .../react-native-worklets/RNWorklets.podspec | 16 ++++- .../android/build.gradle | 16 +++++ .../src/runtimes.native.ts | 2 +- packages/react-native-worklets/src/types.ts | 4 +- 18 files changed, 229 insertions(+), 22 deletions(-) rename packages/react-native-worklets/Common/cpp/worklets/{Public => RunLoop}/AsyncQueue.h (69%) diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index 6d0908d25d58..837c94061750 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -2875,6 +2875,8 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - RNWorklets/worklets/apple (= 0.7.0-main) + - RNWorklets/worklets/common (= 0.7.0-main) + - RNWorklets/worklets/public (= 0.7.0-main) - SocketRocket - Yoga - RNWorklets/worklets/apple (0.7.0-main): @@ -2906,6 +2908,64 @@ PODS: - ReactCommon/turbomodule/core - SocketRocket - Yoga + - RNWorklets/worklets/common (0.7.0-main): + - boost + - DoubleConversion + - fast_float + - fmt + - glog + - hermes-engine + - RCT-Folly + - RCT-Folly/Fabric + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-hermes + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - SocketRocket + - Yoga + - RNWorklets/worklets/public (0.7.0-main): + - boost + - DoubleConversion + - fast_float + - fmt + - glog + - hermes-engine + - RCT-Folly + - RCT-Folly/Fabric + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-hermes + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - SocketRocket + - Yoga - SocketRocket (0.7.1) - Yoga (0.0.0) @@ -3261,7 +3321,7 @@ SPEC CHECKSUMS: RNReanimated: 97ebf4d3c76929b6b0f866cfbd41c49b3a0d2dbf RNScreens: 0bbf16c074ae6bb1058a7bf2d1ae017f4306797c RNSVG: 8c0bbfa480a24b24468f1c76bd852a4aac3178e6 - RNWorklets: f54a415f73a3fc653bfe65e599872fdc6bca0477 + RNWorklets: b2ad4ec784199346ed45f0d2eec051401d383c2d SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 Yoga: edeb9900b9e5bb5b27b9a6a2d5914e4fe4033c1b diff --git a/apps/macos-example/macos/Podfile.lock b/apps/macos-example/macos/Podfile.lock index fe67bd1fef42..85a8ecc6bde4 100644 --- a/apps/macos-example/macos/Podfile.lock +++ b/apps/macos-example/macos/Podfile.lock @@ -1977,6 +1977,8 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - RNWorklets/worklets/apple (= 0.7.0-main) + - RNWorklets/worklets/common (= 0.7.0-main) + - RNWorklets/worklets/public (= 0.7.0-main) - Yoga - RNWorklets/worklets/apple (0.7.0-main): - DoubleConversion @@ -2002,6 +2004,54 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga + - RNWorklets/worklets/common (0.7.0-main): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.11.18.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-hermes + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga + - RNWorklets/worklets/public (0.7.0-main): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.11.18.00) + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-hermes + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga - SocketRocket (0.7.1) - Yoga (0.0.0) @@ -2322,7 +2372,7 @@ SPEC CHECKSUMS: RNGestureHandler: 0397fea67f39d5a2d17fcf4a028e206f7ba098ba RNReanimated: 152207cf096f2badeef2c552a8f2886accd187e6 RNSVG: 681f8ef5ca50e13cb3c6c88a907ea89b68fee74f - RNWorklets: ee84c4d458ce35f4ed94462a2add070ff4e69edb + RNWorklets: 7cdcdb8dd199bc5d1cd99e42940c47e4442a2670 SocketRocket: 03f7111df1a343b162bf5b06ead333be808e1e0a Yoga: 45ce05cb11db042ba2e5e51a2dfaf0ff63d269f9 diff --git a/apps/tvos-example/ios/Podfile.lock b/apps/tvos-example/ios/Podfile.lock index 4bf4190b204b..7594d92ede21 100644 --- a/apps/tvos-example/ios/Podfile.lock +++ b/apps/tvos-example/ios/Podfile.lock @@ -2397,6 +2397,8 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - RNWorklets/worklets/apple (= 0.7.0-main) + - RNWorklets/worklets/common (= 0.7.0-main) + - RNWorklets/worklets/public (= 0.7.0-main) - SocketRocket - Yoga - RNWorklets/worklets/apple (0.7.0-main): @@ -2427,6 +2429,62 @@ PODS: - ReactCommon/turbomodule/core - SocketRocket - Yoga + - RNWorklets/worklets/common (0.7.0-main): + - boost + - DoubleConversion + - fast_float + - fmt + - glog + - hermes-engine + - RCT-Folly + - RCT-Folly/Fabric + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - SocketRocket + - Yoga + - RNWorklets/worklets/public (0.7.0-main): + - boost + - DoubleConversion + - fast_float + - fmt + - glog + - hermes-engine + - RCT-Folly + - RCT-Folly/Fabric + - RCTRequired + - RCTTypeSafety + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-jsi + - React-NativeModulesApple + - React-RCTFabric + - React-renderercss + - React-rendererdebug + - React-utils + - ReactCodegen + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - SocketRocket + - Yoga - SocketRocket (0.7.1) - Yoga (0.0.0) @@ -2732,7 +2790,7 @@ SPEC CHECKSUMS: ReactCodegen: f4d6e6fd5140eade461ffb5579795197956868c8 ReactCommon: c178596d3ef05508bb6c0f88bfbbc281b5c4222b RNReanimated: cccf8b45cb675080e7c5f3a4f5d0498eff6c62a0 - RNWorklets: 339aa12272b2ff6490d91526e8ced6599f7ef6a3 + RNWorklets: 6aa271764dc8121f468b10c866239ca4c644208b SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 Yoga: 0e792f39294e864568930600eeb71135364f777d diff --git a/docs/docs-worklets/docs/threading/scheduleOnRuntime.mdx b/docs/docs-worklets/docs/threading/scheduleOnRuntime.mdx index 9d3b52085ebe..7aada0f8eb83 100644 --- a/docs/docs-worklets/docs/threading/scheduleOnRuntime.mdx +++ b/docs/docs-worklets/docs/threading/scheduleOnRuntime.mdx @@ -48,7 +48,7 @@ Arguments to the function you want to execute on the [Worker Runtime](/docs/fund ## Remarks - The worklet is scheduled on the Worker Runtime's [Async - Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/Public/AsyncQueue.h) + Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h) - The worklet cannot be scheduled on the Worker Runtime from [UI Runtime](/docs/fundamentals/glossary#ui-runtime) or another [Worker Runtime](/docs/fundamentals/glossary#worker-runtime), unless the [Bundle Mode](/docs/experimental/bundleMode) is enabled. diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h index 2964ac3a16f9..521bbf325b53 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include #include diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h index 16de0b56a16b..c5b5c3065fcf 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp index 454eeb1a4cc0..a3d3271e68aa 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp @@ -5,8 +5,8 @@ #include #include +#include #include -#include #include #ifdef __ANDROID__ diff --git a/packages/react-native-reanimated/android/CMakeLists.txt b/packages/react-native-reanimated/android/CMakeLists.txt index d4731e6c9e5b..9f3220d6315e 100644 --- a/packages/react-native-reanimated/android/CMakeLists.txt +++ b/packages/react-native-reanimated/android/CMakeLists.txt @@ -70,7 +70,8 @@ target_include_directories( "${REACT_NATIVE_DIR}/ReactCommon/jsiexecutor" "${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx" "${REACT_NATIVE_WORKLETS_DIR}/Common/cpp" - "${REACT_NATIVE_WORKLETS_DIR}/android/src/main/cpp") + "${REACT_NATIVE_WORKLETS_DIR}/android/src/main/cpp" + "${REACT_NATIVE_WORKLETS_DIR}/android/build/prefab-headers") set_target_properties(reanimated PROPERTIES LINKER_LANGUAGE CXX) diff --git a/packages/react-native-worklets/Common/cpp/worklets/Public/AsyncQueue.h b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h similarity index 69% rename from packages/react-native-worklets/Common/cpp/worklets/Public/AsyncQueue.h rename to packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h index 0ec5146437ad..9ddee394f642 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/Public/AsyncQueue.h +++ b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef RNWORKLETS_ASYNCQUEUE_H +#define RNWORKLETS_ASYNCQUEUE_H #include @@ -12,3 +13,5 @@ class AsyncQueue : public facebook::jsi::NativeState { }; } // namespace worklets + +#endif // RNWORKLETS_ASYNCQUEUE_H diff --git a/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h index 30cd0d7a0292..72592049201b 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +++ b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/packages/react-native-worklets/Common/cpp/worklets/RunLoop/EventLoop.h b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/EventLoop.h index ac3eed1816d1..885bbbe2a8c1 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/RunLoop/EventLoop.h +++ b/packages/react-native-worklets/Common/cpp/worklets/RunLoop/EventLoop.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h index 771b6be96cd9..90b693ae79da 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h +++ b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Serializable.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef RNWORKLETS_SERIALIZABLE_H +#define RNWORKLETS_SERIALIZABLE_H #include @@ -429,3 +430,5 @@ struct SerializationData { }; } // namespace worklets + +#endif // RNWORKLETS_SERIALIZABLE_H diff --git a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Synchronizable.h b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Synchronizable.h index 55e3a56eafb2..b126e0bbb1aa 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Synchronizable.h +++ b/packages/react-native-worklets/Common/cpp/worklets/SharedItems/Synchronizable.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef RNWORKLETS_SYNCHRONIZABLE_H +#define RNWORKLETS_SYNCHRONIZABLE_H #include #include @@ -55,3 +56,5 @@ jsi::Function getSynchronizableUnpacker(jsi::Runtime &rt); std::shared_ptr extractSynchronizableOrThrow(jsi::Runtime &rt, const jsi::Value &value); }; // namespace worklets + +#endif // RNWORKLETS_SYNCHRONIZABLE_H diff --git a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h index 919f0de2e95d..ce5845665c71 100644 --- a/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +++ b/packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h @@ -1,11 +1,12 @@ -#pragma once +#ifndef RNWORKLETS_WORKLETRUNTIME_H +#define RNWORKLETS_WORKLETRUNTIME_H #include #include #include #include -#include +#include #include #include #include @@ -215,3 +216,5 @@ inline jsi::Value runOnRuntimeGuarded(jsi::Runtime &rt, const jsi::Value &functi } } // namespace worklets + +#endif // RNWORKLETS_WORKLETRUNTIME_H diff --git a/packages/react-native-worklets/RNWorklets.podspec b/packages/react-native-worklets/RNWorklets.podspec index fa66aa9ef6f6..44c3e766dd4d 100644 --- a/packages/react-native-worklets/RNWorklets.podspec +++ b/packages/react-native-worklets/RNWorklets.podspec @@ -24,9 +24,11 @@ Pod::Spec.new do |s| 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 "common" do |sss| + sss.source_files = "Common/cpp/worklets/**/*.{h,cpp}" + sss.header_dir = "worklets" + sss.header_mappings_dir = "Common/cpp/worklets" + end ss.subspec "apple" do |sss| # Please be careful with the snakes. @@ -36,6 +38,14 @@ Pod::Spec.new do |s| sss.header_dir = "worklets" sss.header_mappings_dir = "apple/worklets" end + + ss.subspec "public" do |sss| + sss.source_files = + "Common/cpp/worklets/RunLoop/AsyncQueue.h", + "Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h", + "Common/cpp/worklets/SharedItems/Serializable.h", + "Common/cpp/worklets/SharedItems/Synchronizable.h" + end end # Use install_modules_dependencies helper to install the dependencies. diff --git a/packages/react-native-worklets/android/build.gradle b/packages/react-native-worklets/android/build.gradle index 2e5ad454afb1..087c2c7c7d90 100644 --- a/packages/react-native-worklets/android/build.gradle +++ b/packages/react-native-worklets/android/build.gradle @@ -108,6 +108,7 @@ def HERMES_V1_ENABLED = safeAppExtGet("hermesV1Enabled", false) version WORKLETS_VERSION def workletsPrefabHeadersDir = project.file("$buildDir/prefab-headers/worklets") +def RNWorkletsPrefabHeadersDir = project.file("${buildDir}/prefab-headers/RNWorklets") def JS_RUNTIME = { // Override JS runtime with environment variable @@ -172,6 +173,7 @@ android { prefab { worklets { headers workletsPrefabHeadersDir.absolutePath + headers RNWorkletsPrefabHeadersDir.absolutePath } } @@ -315,6 +317,20 @@ task prepareWorkletsHeadersForPrefabs(type: Copy) { from("$projectDir/../Common/cpp") include("worklets/**/*.h") into(workletsPrefabHeadersDir) + + // Pack public headers to RNWorklets headers dir + from("$projectDir/../Common/cpp/worklets/RunLoop/") { + include("AsyncQueue.h") + } + from("$projectDir/../Common/cpp/worklets/WorkletRuntime/") { + include("WorkletRuntime.h") + } + from("$projectDir/../Common/cpp/worklets/SharedItems/") { + include("Serializable.h") + include("Synchronizable.h") + } + into(RNWorkletsPrefabHeadersDir) + } task cleanCmakeCache() { diff --git a/packages/react-native-worklets/src/runtimes.native.ts b/packages/react-native-worklets/src/runtimes.native.ts index 5cd234e89b90..c1cd1dd8c83b 100644 --- a/packages/react-native-worklets/src/runtimes.native.ts +++ b/packages/react-native-worklets/src/runtimes.native.ts @@ -115,7 +115,7 @@ export function createWorkletRuntime( * for more information about the different runtime kinds. * * - The worklet is scheduled on the Worker Runtime's [Async - * Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/Public/AsyncQueue.h) + * Queue](https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-worklets/Common/cpp/worklets/RunLoop/AsyncQueue.h) * - The function cannot be scheduled on the Worker Runtime from [UI * Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-runtime) * or another [Worker diff --git a/packages/react-native-worklets/src/types.ts b/packages/react-native-worklets/src/types.ts index 916e175a4a1f..892e47eb10f9 100644 --- a/packages/react-native-worklets/src/types.ts +++ b/packages/react-native-worklets/src/types.ts @@ -130,7 +130,7 @@ export type WorkletRuntimeConfig = { * An optional custom queue to be used for scheduling worklets. * * The queue has to implement the C++ `AsyncQueue` interface from - * ``. + * ``. */ customQueue?: never; } @@ -144,7 +144,7 @@ export type WorkletRuntimeConfig = { * An optional custom queue to be used for scheduling worklets. * * The queue has to implement the C++ `AsyncQueue` interface from - * ``. + * ``. */ customQueue?: object; }