@react-native-ohos/react-native-reanimated 3.18.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/harmony/reanimated/BuildProfile.ets +17 -0
  2. package/harmony/reanimated/build-profile.json5 +12 -0
  3. package/harmony/reanimated/hvigorfile.ts +5 -0
  4. package/harmony/reanimated/index.ets +5 -0
  5. package/harmony/reanimated/oh-package.json5 +12 -0
  6. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +72 -0
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -0
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -0
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -0
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -0
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -0
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -0
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +87 -0
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -0
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -0
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -0
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -0
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -0
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -0
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -0
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -0
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -0
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -0
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -0
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -0
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -0
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -0
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -0
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -0
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -0
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -0
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -0
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -0
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -0
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -0
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -0
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -0
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -0
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -0
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -0
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -0
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -0
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -0
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -0
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -0
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -0
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -0
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -0
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -0
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -0
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -0
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -0
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -0
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -0
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -0
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -0
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -0
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -0
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -0
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -0
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -0
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -0
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -0
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -0
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +155 -0
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -0
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +182 -0
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -0
  80. package/harmony/reanimated/src/main/cpp/ReanimatedLogger.cpp +33 -0
  81. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +222 -0
  82. package/harmony/reanimated/src/main/cpp/ReanimatedModule.h +24 -0
  83. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +56 -0
  84. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.h +31 -0
  85. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +47 -0
  86. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.h +16 -0
  87. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.cpp +23 -0
  88. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +20 -0
  89. package/harmony/reanimated/src/main/cpp/TransformParser.h +94 -0
  90. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +58 -0
  91. package/harmony/reanimated/src/main/cpp/WorkletsModule.h +22 -0
  92. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -0
  93. package/harmony/reanimated/src/main/cpp/patches/Fabric/ShadowTreeCloner.cpp +95 -0
  94. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +961 -0
  95. package/harmony/reanimated/src/main/ets/AnimationManager.ts +61 -0
  96. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +41 -0
  97. package/harmony/reanimated/src/main/ets/ReanimatedPackage.ts +29 -0
  98. package/harmony/reanimated/src/main/ets/WorkletsModule.ts +15 -0
  99. package/harmony/reanimated/src/main/module.json5 +13 -0
  100. package/harmony/reanimated/src/main/resources/base/element/color.json +8 -0
  101. package/harmony/reanimated/src/main/resources/base/element/string.json +16 -0
  102. package/harmony/reanimated/src/main/resources/base/media/icon.png +0 -0
  103. package/harmony/reanimated/src/main/resources/base/media/startIcon.png +0 -0
  104. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -0
  105. package/harmony/reanimated/src/main/resources/en_US/element/string.json +16 -0
  106. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +16 -0
  107. package/harmony/reanimated/ts.ts +6 -0
  108. package/harmony/reanimated.har +0 -0
  109. package/lib/index.d.ts +4 -0
  110. package/lib/index.d.ts.map +1 -0
  111. package/lib/index.js +7 -0
  112. package/package.json +50 -0
  113. package/src/index.ts +10 -0
@@ -0,0 +1,31 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #pragma once
6
+ #include <vector>
7
+ #include <functional>
8
+ #include <native_vsync/native_vsync.h>
9
+ #include "RNOH/NativeVsyncHandle.h"
10
+ #include "RNOH/TaskExecutor/TaskExecutor.h"
11
+
12
+ using ReanimatedPerformOperations = std::function<void()>;
13
+ using ReanimatedOnAnimationCallback = std::function<void(double)>;
14
+ using ReanimatedEventHandler = std::function<void()>;
15
+ namespace rnoh {
16
+ class ReanimatedNodesManager : public std::enable_shared_from_this<ReanimatedNodesManager> {
17
+ ReanimatedPerformOperations performOperations;
18
+ std::vector<ReanimatedOnAnimationCallback> onAnimationCallbacks;
19
+ NativeVsyncHandle m_vsyncHandle;
20
+ std::function<void(TaskExecutor::Task &&)> runOnTheMainThread;
21
+
22
+ public:
23
+ ReanimatedNodesManager(std::function<void(TaskExecutor::Task &&)> runOnTheMainThread);
24
+ ~ReanimatedNodesManager() noexcept = default;
25
+ void maybeFlushUIUpdatesQueue();
26
+ void registerPerformOperations(ReanimatedPerformOperations reanimatedPerformOperations);
27
+ void postOnAnimation(ReanimatedOnAnimationCallback callback);
28
+ void operationBatchDidComplete();
29
+ void onAnimationFrame(int64_t timestamp);
30
+ };
31
+ } // namespace rnoh
@@ -0,0 +1,47 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "ReanimatedPackage.h"
6
+ #include "ReanimatedModule.h"
7
+ #include "WorkletsModule.h"
8
+
9
+ using namespace rnoh;
10
+ using namespace facebook;
11
+
12
+ class ReanimatedTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
13
+ public:
14
+ SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override
15
+ {
16
+ if (name == "ReanimatedModule") {
17
+ return std::make_shared<ReanimatedModule>(ctx, name);
18
+ } else if (name == "WorkletsModule") {
19
+ return std::make_shared<worklets::WorkletsModule>(ctx, name);
20
+ }
21
+ return nullptr;
22
+ };
23
+ };
24
+
25
+ std::unique_ptr<TurboModuleFactoryDelegate> ReanimatedPackage::createTurboModuleFactoryDelegate()
26
+ {
27
+ return std::make_unique<ReanimatedTurboModuleFactoryDelegate>();
28
+ }
29
+
30
+ class ReanimatedArkTsMessage : public ArkTSMessageHandler {
31
+ void handleArkTSMessage(const Context &ctx) override
32
+ {
33
+ auto rnInstance = ctx.rnInstance.lock();
34
+ if (rnInstance) {
35
+ if (ctx.messageName == "REANIMATED_KEY_BOARD_CHANGE") {
36
+ auto keyboardHeight = ctx.messagePayload["keyboardHeight"].asDouble();
37
+ auto status = ctx.messagePayload["status"].asInt();
38
+ rnInstance->getTurboModule<ReanimatedModule>("ReanimatedModule")->callKeyBord(keyboardHeight, status);
39
+ }
40
+ }
41
+ }
42
+ };
43
+
44
+ std::vector<ArkTSMessageHandler::Shared> ReanimatedPackage::createArkTSMessageHandlers()
45
+ {
46
+ return { std::make_shared<ReanimatedArkTsMessage>() };
47
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "RNOH/Package.h"
6
+
7
+ namespace rnoh {
8
+ class ReanimatedPackage : public Package {
9
+ public:
10
+ ReanimatedPackage(Package::Context ctx) : Package(ctx) {}
11
+
12
+ std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override;
13
+
14
+ std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
15
+ };
16
+ } // namespace rnoh
@@ -0,0 +1,23 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "ReanimatedUIScheduler.h"
6
+
7
+ namespace rnoh {
8
+ ReanimatedUIScheduler::ReanimatedUIScheduler(std::shared_ptr<TaskExecutor> taskExecutor) : m_taskExecutor(taskExecutor)
9
+ {}
10
+ void ReanimatedUIScheduler::scheduleOnUI(std::function<void()> job)
11
+ {
12
+ if (m_taskExecutor->isOnTaskThread(TaskThread::MAIN)) {
13
+ job();
14
+ return;
15
+ }
16
+
17
+ m_taskExecutor->runTask(TaskThread::MAIN, [weakSelf = weak_from_this(), job = std::move(job)]() {
18
+ if (auto self = weakSelf.lock()) {
19
+ job();
20
+ }
21
+ });
22
+ }
23
+ } // namespace rnoh
@@ -0,0 +1,20 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #pragma once
6
+ #include <functional>
7
+ #include <UIScheduler.h>
8
+ #include <memory>
9
+ #include "RNOH/TaskExecutor/TaskExecutor.h"
10
+
11
+ namespace rnoh {
12
+ class ReanimatedUIScheduler : public std::enable_shared_from_this<ReanimatedUIScheduler>, public worklets::UIScheduler {
13
+ private:
14
+ std::shared_ptr<TaskExecutor> m_taskExecutor;
15
+
16
+ public:
17
+ ReanimatedUIScheduler(std::shared_ptr<TaskExecutor> taskExecutor);
18
+ void scheduleOnUI(std::function<void()> job) override;
19
+ };
20
+ } // namespace rnoh
@@ -0,0 +1,94 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include <folly/dynamic.h>
6
+ #include <react/renderer/graphics/Transform.h>
7
+ #define _USE_MATH_DEFINES
8
+ #include <cmath>
9
+
10
+ namespace rnoh {
11
+ facebook::react::Transform applyTransformOperation(facebook::react::Transform const & transform,
12
+ std::string const & property, double value)
13
+ {
14
+ facebook::react::Transform operation;
15
+ if (property == "translateX") {
16
+ operation = facebook::react::Transform::Translate(value, 0, 0);
17
+ } else if (property == "translateY") {
18
+ operation = facebook::react::Transform::Translate(0, value, 0);
19
+ } else if (property == "scale") {
20
+ operation = facebook::react::Transform::Scale(value, value, 1);
21
+ } else if (property == "scaleX") {
22
+ operation = facebook::react::Transform::Scale(value, 1, 1);
23
+ } else if (property == "scaleY") {
24
+ operation = facebook::react::Transform::Scale(1, value, 1);
25
+ } else if (property == "rotate") {
26
+ operation = facebook::react::Transform::Rotate(0, 0, value);
27
+ } else if (property == "rotateX") {
28
+ operation = facebook::react::Transform::Rotate(value, 0, 0);
29
+ } else if (property == "rotateY") {
30
+ operation = facebook::react::Transform::Rotate(0, value, 0);
31
+ } else if (property == "rotateZ") {
32
+ operation = facebook::react::Transform::Rotate(0, 0, value);
33
+ } else if (property == "perspective") {
34
+ operation = facebook::react::Transform::Perspective(value);
35
+ } else if (property == "skewX") {
36
+ operation = facebook::react::Transform::Skew(value, 0);
37
+ } else if (property == "skewY") {
38
+ operation = facebook::react::Transform::Skew(0, value);
39
+ } else {
40
+ throw std::runtime_error("Unsupported transform property " + property);
41
+ }
42
+ return transform * operation;
43
+ }
44
+
45
+ double convertStringAngleValueToRadians(std::string angle)
46
+ {
47
+ auto unit = angle.substr(angle.length() - 3);
48
+ auto value = std::stod(angle.substr(0, angle.length() - 3));
49
+ if (unit == "rad") {
50
+ return value;
51
+ } else if (unit == "deg") {
52
+ return (value * M_PI) / 180;
53
+ }
54
+
55
+ throw std::invalid_argument("Angle must be a value in radians or degrees");
56
+ }
57
+
58
+ folly::dynamic parseTransform(folly::dynamic &dynamicTransform)
59
+ {
60
+ facebook::react::Transform resultTransform = facebook::react::Transform::Identity();
61
+ for (auto &singleTransform : dynamicTransform) {
62
+ for (auto &item : singleTransform.items()) {
63
+ auto transformType = item.first.getString();
64
+ if (transformType == "matrix") {
65
+ auto matrixTransform = facebook::react::Transform::Identity();
66
+ if (item.second.size() == 16) {
67
+ for (size_t i = 0; i < 16; ++i) {
68
+ matrixTransform.matrix[i] = item.second[i].getDouble();
69
+ }
70
+ }
71
+ resultTransform = resultTransform * matrixTransform;
72
+ } else {
73
+ double transformValue;
74
+ if (item.second.isString()) {
75
+ try {
76
+ transformValue = convertStringAngleValueToRadians(item.second.getString());
77
+ } catch (std::invalid_argument &e) {
78
+ // ignore incorrect values
79
+ continue;
80
+ }
81
+ } else if (item.second.isDouble()) {
82
+ transformValue = item.second.getDouble();
83
+ } else {
84
+ // ignore incorrect values
85
+ continue;
86
+ }
87
+ resultTransform = applyTransformOperation(resultTransform, transformType, transformValue);
88
+ }
89
+ }
90
+ }
91
+ auto const & matrix = resultTransform.matrix;
92
+ return folly::dynamic::array(matrix.begin(), matrix.end());
93
+ }
94
+ }
@@ -0,0 +1,58 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #include "RNOH/ArkTSTurboModule.h"
6
+ #include "ReanimatedUIScheduler.h"
7
+ #include "WorkletsModule.h"
8
+ #include "RNRuntimeWorkletDecorator.h"
9
+ #include "PlatformLogger.h"
10
+
11
+ using namespace facebook;
12
+ namespace worklets {
13
+ jsi::Value installTurboModule(facebook::jsi::Runtime &rt, react::TurboModule &turboModule,
14
+ const facebook::jsi::Value *args, size_t count)
15
+ {
16
+ auto self = static_cast<WorkletsModule *>(&turboModule);
17
+ if (count < 1) {
18
+ LOG(ERROR) << "WorkletsModule: Missing required argument";
19
+ return facebook::jsi::Value(false);
20
+ }
21
+ if (!args[0].isString()) {
22
+ LOG(ERROR) << "WorkletsModule: First argument must be a string";
23
+ return facebook::jsi::Value(false);
24
+ }
25
+
26
+ std::string valueUnpackerCode = args[0].getString(rt).utf8(rt);
27
+ self->installTurboModule(rt, valueUnpackerCode);
28
+ return facebook::jsi::Value(true);
29
+ }
30
+
31
+ WorkletsModule::WorkletsModule(const ArkTSTurboModule::Context ctx, const std::string name)
32
+ : ArkTSTurboModule(ctx, name)
33
+ {
34
+ methodMap_ = { { "installTurboModule", { 0, worklets::installTurboModule } } };
35
+ }
36
+
37
+ WorkletsModule::~WorkletsModule()
38
+ {
39
+ LOG(INFO) << "WorkletsModule::~WorkletsModule";
40
+ }
41
+
42
+ void WorkletsModule::installTurboModule(facebook::jsi::Runtime &runtime, std::string valueUnpackerCode)
43
+ {
44
+ if (workletsModuleProxy_) {
45
+ LOG(WARNING) << "WorkletsModuleProxy already initialized";
46
+ return;
47
+ }
48
+
49
+ workletsModuleProxy_ = std::make_shared<WorkletsModuleProxy>(valueUnpackerCode, m_ctx.jsQueue, jsInvoker_,
50
+ std::make_shared<worklets::JSScheduler>(runtime, jsInvoker_),
51
+ std::make_shared<rnoh::ReanimatedUIScheduler>(m_ctx.taskExecutor));
52
+ RNRuntimeWorkletDecorator::decorate(runtime, workletsModuleProxy_);
53
+ }
54
+ std::shared_ptr<worklets::WorkletsModuleProxy> WorkletsModule::getWorkletsModuleProxy()
55
+ {
56
+ return workletsModuleProxy_;
57
+ }
58
+ } // namespace worklets
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a MIT license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #pragma once
6
+
7
+ #include "RNOH/ArkTSTurboModule.h"
8
+ #include "worklets/NativeModules/WorkletsModuleProxy.h"
9
+
10
+ namespace worklets {
11
+
12
+ class JSI_EXPORT WorkletsModule : public std::enable_shared_from_this<WorkletsModule>, public rnoh::ArkTSTurboModule {
13
+ public:
14
+ WorkletsModule(const ArkTSTurboModule::Context ctx, const std::string name);
15
+ ~WorkletsModule() override;
16
+ void installTurboModule(facebook::jsi::Runtime &rt, const std::string valueUnpackerCode);
17
+ std::shared_ptr<worklets::WorkletsModuleProxy> getWorkletsModuleProxy();
18
+ private:
19
+ std::shared_ptr<worklets::WorkletsModuleProxy> workletsModuleProxy_ = nullptr;
20
+ };
21
+
22
+ } // namespace worklets
@@ -0,0 +1,89 @@
1
+ #include <reanimated/AnimatedSensor/AnimatedSensorModule.h>
2
+
3
+ #include <utility>
4
+
5
+ namespace reanimated {
6
+
7
+ AnimatedSensorModule::AnimatedSensorModule(
8
+ const PlatformDepMethodsHolder &platformDepMethodsHolder)
9
+ : platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
10
+ platformUnregisterSensorFunction_(
11
+ platformDepMethodsHolder.unregisterSensor) {}
12
+
13
+ AnimatedSensorModule::~AnimatedSensorModule() {
14
+ assert(sensorsIds_.empty());
15
+ }
16
+
17
+ jsi::Value AnimatedSensorModule::registerSensor(
18
+ jsi::Runtime &rt,
19
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
20
+ const jsi::Value &sensorTypeValue,
21
+ const jsi::Value &interval,
22
+ const jsi::Value &iosReferenceFrame,
23
+ const jsi::Value &sensorDataHandler) {
24
+ SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());
25
+
26
+ auto shareableHandler = extractShareableOrThrow<ShareableWorklet>(
27
+ rt,
28
+ sensorDataHandler,
29
+ "[Reanimated] Sensor event handler must be a worklet.");
30
+
31
+ int sensorId = platformRegisterSensorFunction_(
32
+ sensorType,
33
+ interval.asNumber(),
34
+ iosReferenceFrame.asNumber(),
35
+ [sensorType,
36
+ shareableHandler,
37
+ weakUiWorkletRuntime = std::weak_ptr<WorkletRuntime>(uiWorkletRuntime)](
38
+ double newValues[], int orientationDegrees) {
39
+ auto uiWorkletRuntime = weakUiWorkletRuntime.lock();
40
+ if (uiWorkletRuntime == nullptr) {
41
+ return;
42
+ }
43
+
44
+ jsi::Runtime &uiRuntime = uiWorkletRuntime->getJSIRuntime();
45
+ jsi::Object value(uiRuntime);
46
+ if (sensorType == SensorType::ROTATION_VECTOR) {
47
+ // TODO: timestamp should be provided by the platform implementation
48
+ // such that the native side has a chance of providing a true event
49
+ // timestamp
50
+ value.setProperty(uiRuntime, "qx", newValues[0]);
51
+ value.setProperty(uiRuntime, "qy", newValues[1]);
52
+ value.setProperty(uiRuntime, "qz", newValues[2]);
53
+ value.setProperty(uiRuntime, "qw", newValues[3]);
54
+ value.setProperty(uiRuntime, "yaw", newValues[4]);
55
+ value.setProperty(uiRuntime, "pitch", newValues[5]);
56
+ value.setProperty(uiRuntime, "roll", newValues[6]);
57
+ } else {
58
+ value.setProperty(uiRuntime, "x", newValues[0]);
59
+ value.setProperty(uiRuntime, "y", newValues[1]);
60
+ value.setProperty(uiRuntime, "z", newValues[2]);
61
+ }
62
+ value.setProperty(
63
+ uiRuntime, "interfaceOrientation", orientationDegrees);
64
+
65
+ uiWorkletRuntime->runGuarded(shareableHandler, value);
66
+ });
67
+ if (sensorId != -1) {
68
+ sensorsIds_.insert(sensorId);
69
+ }
70
+ return jsi::Value(sensorId);
71
+ }
72
+
73
+ void AnimatedSensorModule::unregisterSensor(const jsi::Value &sensorId) {
74
+ // It is called during sensor hook unmounting
75
+ if (!sensorId.isNumber()) {
76
+ return;
77
+ }
78
+ sensorsIds_.erase(sensorId.getNumber());
79
+ platformUnregisterSensorFunction_(sensorId.asNumber());
80
+ }
81
+
82
+ void AnimatedSensorModule::unregisterAllSensors() {
83
+ for (auto sensorId : sensorsIds_) {
84
+ platformUnregisterSensorFunction_(sensorId);
85
+ }
86
+ sensorsIds_.clear();
87
+ }
88
+
89
+ } // namespace reanimated
@@ -0,0 +1,95 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #include <reanimated/Fabric/ShadowTreeCloner.h>
4
+
5
+ #include <ranges>
6
+ #include <utility>
7
+
8
+ namespace reanimated {
9
+
10
+ Props::Shared mergeProps(
11
+ const ShadowNode &shadowNode,
12
+ const PropsMap &propsMap,
13
+ const ShadowNodeFamily &family) {
14
+ const auto it = propsMap.find(&family);
15
+
16
+ if (it == propsMap.end()) {
17
+ return ShadowNodeFragment::propsPlaceholder();
18
+ }
19
+
20
+ PropsParserContext propsParserContext{
21
+ shadowNode.getSurfaceId(), *shadowNode.getContextContainer()};
22
+ const auto &propsVector = it->second;
23
+ auto newProps = shadowNode.getProps();
24
+
25
+ #ifdef ANDROID
26
+ if (propsVector.size() > 1) {
27
+ folly::dynamic newPropsDynamic = folly::dynamic::object;
28
+ for (const auto &props : propsVector) {
29
+ newPropsDynamic = folly::dynamic::merge(
30
+ props.operator folly::dynamic(), newPropsDynamic);
31
+ }
32
+ return shadowNode.getComponentDescriptor().cloneProps(
33
+ propsParserContext, newProps, RawProps(newPropsDynamic));
34
+ }
35
+ #endif
36
+
37
+ for (const auto &props : propsVector) {
38
+ newProps = shadowNode.getComponentDescriptor().cloneProps(
39
+ propsParserContext, newProps, RawProps(props));
40
+ }
41
+
42
+ return newProps;
43
+ }
44
+
45
+ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(
46
+ const ShadowNode &shadowNode,
47
+ const ChildrenMap &childrenMap,
48
+ const PropsMap &propsMap) {
49
+ const auto family = &shadowNode.getFamily();
50
+ const auto affectedChildrenIt = childrenMap.find(family);
51
+ auto children = shadowNode.getChildren();
52
+
53
+ if (affectedChildrenIt != childrenMap.end()) {
54
+ for (const auto index : affectedChildrenIt->second) {
55
+ children[index] = cloneShadowTreeWithNewPropsRecursive(
56
+ *children[index], childrenMap, propsMap);
57
+ }
58
+ }
59
+
60
+ return shadowNode.clone(
61
+ {mergeProps(shadowNode, propsMap, *family),
62
+ std::make_shared<ShadowNode::ListOfShared>(children),
63
+ shadowNode.getState()});
64
+ }
65
+
66
+ RootShadowNode::Unshared cloneShadowTreeWithNewProps(
67
+ const RootShadowNode &oldRootNode,
68
+ const PropsMap &propsMap) {
69
+ ChildrenMap childrenMap;
70
+
71
+ for (auto &[family, _] : propsMap) {
72
+ const auto ancestors = family->getAncestors(oldRootNode);
73
+
74
+ for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) {
75
+ const auto &[parentNode, index] = *it;
76
+ const auto parentFamily = &parentNode.get().getFamily();
77
+ auto &affectedChildren = childrenMap[parentFamily];
78
+
79
+ if (affectedChildren.contains(index)) {
80
+ continue;
81
+ }
82
+
83
+ affectedChildren.insert(index);
84
+ }
85
+ }
86
+
87
+ // This cast is safe, because this function returns a clone
88
+ // of the oldRootNode, which is an instance of RootShadowNode
89
+ return std::static_pointer_cast<RootShadowNode>(
90
+ cloneShadowTreeWithNewPropsRecursive(oldRootNode, childrenMap, propsMap));
91
+ }
92
+
93
+ } // namespace reanimated
94
+
95
+ #endif // RCT_NEW_ARCH_ENABLED