@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,90 @@
1
+ #pragma once
2
+
3
+ #include <cxxreact/MessageQueueThread.h>
4
+ #include <jsi/jsi.h>
5
+
6
+ #include <worklets/SharedItems/Shareables.h>
7
+ #include <worklets/Tools/AsyncQueue.h>
8
+ #include <worklets/Tools/JSScheduler.h>
9
+
10
+ #include <memory>
11
+ #include <string>
12
+ #include <utility>
13
+ #include <vector>
14
+
15
+ using namespace facebook;
16
+ using namespace react;
17
+
18
+ namespace worklets {
19
+
20
+ class WorkletRuntime : public jsi::HostObject,
21
+ public std::enable_shared_from_this<WorkletRuntime> {
22
+ public:
23
+ explicit WorkletRuntime(
24
+ jsi::Runtime &rnRuntime,
25
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
26
+ const std::shared_ptr<JSScheduler> &jsScheduler,
27
+ const std::string &name,
28
+ const bool supportsLocking,
29
+ const std::string &valueUnpackerCode);
30
+
31
+ jsi::Runtime &getJSIRuntime() const {
32
+ return *runtime_;
33
+ }
34
+
35
+ template <typename... Args>
36
+ inline jsi::Value runGuarded(
37
+ const std::shared_ptr<ShareableWorklet> &shareableWorklet,
38
+ Args &&...args) const {
39
+ jsi::Runtime &rt = *runtime_;
40
+ return runOnRuntimeGuarded(
41
+ rt, shareableWorklet->toJSValue(rt), std::forward<Args>(args)...);
42
+ }
43
+
44
+ void runAsyncGuarded(
45
+ const std::shared_ptr<ShareableWorklet> &shareableWorklet) {
46
+ if (queue_ == nullptr) {
47
+ queue_ = std::make_shared<AsyncQueue>(name_);
48
+ }
49
+ queue_->push([=, weakThis = weak_from_this()] {
50
+ auto strongThis = weakThis.lock();
51
+ if (!strongThis) {
52
+ return;
53
+ }
54
+
55
+ strongThis->runGuarded(shareableWorklet);
56
+ });
57
+ }
58
+
59
+ jsi::Value executeSync(jsi::Runtime &rt, const jsi::Value &worklet) const;
60
+
61
+ std::string toString() const {
62
+ return "[WorkletRuntime \"" + name_ + "\"]";
63
+ }
64
+
65
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override;
66
+
67
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
68
+
69
+ private:
70
+ const std::shared_ptr<std::recursive_mutex> runtimeMutex_;
71
+ const std::shared_ptr<jsi::Runtime> runtime_;
72
+ #ifndef NDEBUG
73
+ const bool supportsLocking_;
74
+ #endif
75
+ const std::string name_;
76
+ std::shared_ptr<AsyncQueue> queue_;
77
+ };
78
+
79
+ // This function needs to be non-inline to avoid problems with dynamic_cast on
80
+ // Android
81
+ std::shared_ptr<WorkletRuntime> extractWorkletRuntime(
82
+ jsi::Runtime &rt,
83
+ const jsi::Value &value);
84
+
85
+ void scheduleOnRuntime(
86
+ jsi::Runtime &rt,
87
+ const jsi::Value &workletRuntimeValue,
88
+ const jsi::Value &shareableWorkletValue);
89
+
90
+ } // namespace worklets
@@ -0,0 +1,36 @@
1
+ #pragma once
2
+
3
+ #include <worklets/Registries/WorkletRuntimeRegistry.h>
4
+
5
+ #include <jsi/jsi.h>
6
+
7
+ #include <memory>
8
+
9
+ namespace worklets {
10
+
11
+ class WorkletRuntimeCollector : public jsi::HostObject {
12
+ // When worklet runtime is created, we inject an instance of this class as a
13
+ // `jsi::HostObject` into the global object. When worklet runtime is
14
+ // terminated, the object is garbage-collected, which runs the C++ destructor.
15
+ // In the destructor, we unregister the worklet runtime from the registry.
16
+
17
+ public:
18
+ explicit WorkletRuntimeCollector(jsi::Runtime &runtime) : runtime_(runtime) {
19
+ WorkletRuntimeRegistry::registerRuntime(runtime_);
20
+ }
21
+
22
+ ~WorkletRuntimeCollector() {
23
+ WorkletRuntimeRegistry::unregisterRuntime(runtime_);
24
+ }
25
+
26
+ static void install(jsi::Runtime &rt) {
27
+ auto collector = std::make_shared<WorkletRuntimeCollector>(rt);
28
+ auto object = jsi::Object::createFromHostObject(rt, collector);
29
+ rt.global().setProperty(rt, "__workletRuntimeCollector", object);
30
+ }
31
+
32
+ private:
33
+ jsi::Runtime &runtime_;
34
+ };
35
+
36
+ } // namespace worklets
@@ -0,0 +1,182 @@
1
+ #include <worklets/SharedItems/Shareables.h>
2
+ #include <worklets/Tools/JSISerializer.h>
3
+ #include <worklets/Tools/PlatformLogger.h>
4
+ #include <worklets/Tools/ReanimatedJSIUtils.h>
5
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
6
+ #include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
7
+
8
+ #include <vector>
9
+
10
+ namespace worklets {
11
+
12
+ static inline double performanceNow() {
13
+ // copied from JSExecutor.cpp
14
+ auto time = std::chrono::steady_clock::now();
15
+ auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
16
+ time.time_since_epoch())
17
+ .count();
18
+
19
+ constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;
20
+ return duration / NANOSECONDS_IN_MILLISECOND;
21
+ }
22
+
23
+ static inline std::vector<jsi::Value> parseArgs(
24
+ jsi::Runtime &rt,
25
+ std::shared_ptr<ShareableArray> shareableArgs) {
26
+ if (shareableArgs == nullptr) {
27
+ return {};
28
+ }
29
+
30
+ auto argsArray = shareableArgs->toJSValue(rt).asObject(rt).asArray(rt);
31
+ auto argsSize = argsArray.size(rt);
32
+ std::vector<jsi::Value> result(argsSize);
33
+ for (size_t i = 0; i < argsSize; i++) {
34
+ result[i] = argsArray.getValueAtIndex(rt, i);
35
+ }
36
+ return result;
37
+ }
38
+
39
+ void WorkletRuntimeDecorator::decorate(
40
+ jsi::Runtime &rt,
41
+ const std::string &name,
42
+ const std::shared_ptr<JSScheduler> &jsScheduler) {
43
+ // resolves "ReferenceError: Property 'global' doesn't exist at ..."
44
+ rt.global().setProperty(rt, "global", rt.global());
45
+
46
+ rt.global().setProperty(rt, "_WORKLET", true);
47
+
48
+ rt.global().setProperty(rt, "_LABEL", jsi::String::createFromAscii(rt, name));
49
+
50
+ #ifdef RCT_NEW_ARCH_ENABLED
51
+ constexpr auto isFabric = true;
52
+ #else
53
+ constexpr auto isFabric = false;
54
+ #endif // RCT_NEW_ARCH_ENABLED
55
+ rt.global().setProperty(rt, "_IS_FABRIC", isFabric);
56
+
57
+ #ifndef NDEBUG
58
+ auto evalWithSourceUrl = [](jsi::Runtime &rt,
59
+ const jsi::Value &thisValue,
60
+ const jsi::Value *args,
61
+ size_t count) -> jsi::Value {
62
+ auto code = std::make_shared<const jsi::StringBuffer>(
63
+ args[0].asString(rt).utf8(rt));
64
+ std::string url;
65
+ if (count > 1 && args[1].isString()) {
66
+ url = args[1].asString(rt).utf8(rt);
67
+ }
68
+ return rt.evaluateJavaScript(code, url);
69
+ };
70
+ rt.global().setProperty(
71
+ rt,
72
+ "evalWithSourceUrl",
73
+ jsi::Function::createFromHostFunction(
74
+ rt,
75
+ jsi::PropNameID::forAscii(rt, "evalWithSourceUrl"),
76
+ 1,
77
+ evalWithSourceUrl));
78
+ #endif // NDEBUG
79
+
80
+ jsi_utils::installJsiFunction(
81
+ rt, "_log", [](jsi::Runtime &rt, const jsi::Value &value) {
82
+ PlatformLogger::log(stringifyJSIValue(rt, value));
83
+ });
84
+
85
+ jsi_utils::installJsiFunction(
86
+ rt, "_toString", [](jsi::Runtime &rt, const jsi::Value &value) {
87
+ return jsi::String::createFromUtf8(rt, stringifyJSIValue(rt, value));
88
+ });
89
+
90
+ jsi_utils::installJsiFunction(
91
+ rt,
92
+ "_makeShareableClone",
93
+ [](jsi::Runtime &rt,
94
+ const jsi::Value &value,
95
+ const jsi::Value &nativeStateSource) {
96
+ auto shouldRetainRemote = jsi::Value::undefined();
97
+ return makeShareableClone(
98
+ rt, value, shouldRetainRemote, nativeStateSource);
99
+ });
100
+
101
+ jsi_utils::installJsiFunction(
102
+ rt,
103
+ "_scheduleRemoteFunctionOnJS",
104
+ [jsScheduler](
105
+ jsi::Runtime &rt,
106
+ const jsi::Value &funValue,
107
+ const jsi::Value &argsValue) {
108
+ auto shareableRemoteFun = extractShareableOrThrow<
109
+ ShareableRemoteFunction>(
110
+ rt,
111
+ funValue,
112
+ "[Reanimated] Incompatible object passed to scheduleOnJS. It is only allowed to schedule worklets or functions defined on the React Native JS runtime this way.");
113
+
114
+ auto shareableArgs = argsValue.isUndefined()
115
+ ? nullptr
116
+ : extractShareableOrThrow<ShareableArray>(
117
+ rt, argsValue, "[Reanimated] Args must be an array.");
118
+
119
+ jsScheduler->scheduleOnJS([=](jsi::Runtime &rt) {
120
+ auto fun =
121
+ shareableRemoteFun->toJSValue(rt).asObject(rt).asFunction(rt);
122
+ if (shareableArgs == nullptr) {
123
+ // fast path for remote function w/o arguments
124
+ fun.call(rt);
125
+ } else {
126
+ auto args = parseArgs(rt, shareableArgs);
127
+ fun.call(
128
+ rt, const_cast<const jsi::Value *>(args.data()), args.size());
129
+ }
130
+ });
131
+ });
132
+
133
+ jsi_utils::installJsiFunction(
134
+ rt,
135
+ "_scheduleHostFunctionOnJS",
136
+ [jsScheduler](
137
+ jsi::Runtime &rt,
138
+ const jsi::Value &hostFunValue,
139
+ const jsi::Value &argsValue) {
140
+ auto hostFun =
141
+ hostFunValue.asObject(rt).asFunction(rt).getHostFunction(rt);
142
+
143
+ auto shareableArgs = argsValue.isUndefined()
144
+ ? nullptr
145
+ : extractShareableOrThrow<ShareableArray>(
146
+ rt, argsValue, "[Reanimated] Args must be an array.");
147
+
148
+ jsScheduler->scheduleOnJS([=](jsi::Runtime &rt) {
149
+ auto args = parseArgs(rt, shareableArgs);
150
+ hostFun(
151
+ rt,
152
+ jsi::Value::undefined(),
153
+ const_cast<const jsi::Value *>(args.data()),
154
+ args.size());
155
+ });
156
+ });
157
+
158
+ jsi_utils::installJsiFunction(
159
+ rt,
160
+ "_scheduleOnRuntime",
161
+ [](jsi::Runtime &rt,
162
+ const jsi::Value &workletRuntimeValue,
163
+ const jsi::Value &shareableWorkletValue) {
164
+ scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
165
+ });
166
+
167
+ jsi::Object performance(rt);
168
+ performance.setProperty(
169
+ rt,
170
+ "now",
171
+ jsi::Function::createFromHostFunction(
172
+ rt,
173
+ jsi::PropNameID::forAscii(rt, "now"),
174
+ 0,
175
+ [](jsi::Runtime &runtime,
176
+ const jsi::Value &,
177
+ const jsi::Value *args,
178
+ size_t count) { return jsi::Value(performanceNow()); }));
179
+ rt.global().setProperty(rt, "performance", performance);
180
+ }
181
+
182
+ } // namespace worklets
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+
3
+ #include <worklets/Tools/JSScheduler.h>
4
+
5
+ #include <jsi/jsi.h>
6
+
7
+ #include <memory>
8
+ #include <string>
9
+
10
+ using namespace facebook;
11
+
12
+ namespace worklets {
13
+
14
+ class WorkletRuntimeDecorator {
15
+ public:
16
+ static void decorate(
17
+ jsi::Runtime &rt,
18
+ const std::string &name,
19
+ const std::shared_ptr<JSScheduler> &jsScheduler);
20
+ };
21
+
22
+ } // namespace worklets
@@ -0,0 +1,33 @@
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 <PlatformLogger.h>
6
+ #include "glog/logging.h"
7
+
8
+ namespace worklets {
9
+ void PlatformLogger::log(const char *str)
10
+ {
11
+ LOG(INFO) << str;
12
+ }
13
+
14
+ void PlatformLogger::log(const std::string &str)
15
+ {
16
+ log(str.c_str());
17
+ }
18
+
19
+ void PlatformLogger::log(const double d)
20
+ {
21
+ LOG(INFO) << d;
22
+ }
23
+
24
+ void PlatformLogger::log(const int i)
25
+ {
26
+ LOG(INFO) << i;
27
+ }
28
+
29
+ void PlatformLogger::log(const bool b)
30
+ {
31
+ LOG(INFO) << b;
32
+ }
33
+ } // namespace worklets
@@ -0,0 +1,222 @@
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 "RNOH/RNInstance.h"
7
+ #include "ReanimatedModule.h"
8
+ #include "ReanimatedUIScheduler.h"
9
+ #include "PlatformDepMethodsHolder.h"
10
+ #include "WorkletRuntimeCollector.h"
11
+ #include "RNRuntimeDecorator.h"
12
+ #include "TransformParser.h"
13
+ #include "RNOH/RNInstanceCAPI.h"
14
+ #include "WorkletsModule.h"
15
+
16
+ using namespace facebook;
17
+ using namespace reanimated;
18
+ using namespace worklets;
19
+ namespace rnoh {
20
+ static double getMillisSinceEpoch()
21
+ {
22
+ auto now = std::chrono::high_resolution_clock::now();
23
+ auto frameTime = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
24
+ return frameTime.count();
25
+ }
26
+
27
+ jsi::Value installTurboModule(facebook::jsi::Runtime &rt, react::TurboModule &turboModule,
28
+ const facebook::jsi::Value *args, size_t count)
29
+ {
30
+ auto self = static_cast<ReanimatedModule *>(&turboModule);
31
+ self->installTurboModule(rt);
32
+ return facebook::jsi::Value(true);
33
+ }
34
+
35
+ ReanimatedModule::ReanimatedModule(const ArkTSTurboModule::Context ctx, const std::string name)
36
+ : ArkTSTurboModule(ctx, name)
37
+ {
38
+ methodMap_ = { { "installTurboModule", { 0, rnoh::installTurboModule } } };
39
+ }
40
+
41
+ ReanimatedModule::~ReanimatedModule()
42
+ {
43
+ LOG(INFO) << "ReanimatedModule::~ReanimatedModule";
44
+ if (eventListener) {
45
+ m_ctx.scheduler->removeEventListener(eventListener);
46
+ }
47
+ if (keyboardEventDataUpdater_) {
48
+ keyboardEventDataUpdater_ = nullptr;
49
+ }
50
+ }
51
+
52
+ void ReanimatedModule::installTurboModule(facebook::jsi::Runtime &rt)
53
+ {
54
+ auto nodesManager = std::make_shared<ReanimatedNodesManager>(
55
+ [weakExecutor = std::weak_ptr(m_ctx.taskExecutor)](TaskExecutor::Task &&task) {
56
+ if (auto taskExecutor = weakExecutor.lock()) {
57
+ taskExecutor->runTask(TaskThread::MAIN, std::move(task));
58
+ }
59
+ });
60
+
61
+ auto maybeFlushUIUpdatesQueueFunction = [nodesManager]() { nodesManager->maybeFlushUIUpdatesQueue(); };
62
+ auto requestRender = [weakSelf = weak_from_this(), nodesManager](std::function<void(double)> onRender) {
63
+ auto self = weakSelf.lock();
64
+ if (!self) {
65
+ return;
66
+ }
67
+
68
+ nodesManager->postOnAnimation(
69
+ [weakReanimatedModule = self->weakNativeReanimatedModule_, onRender = std::move(onRender)](auto frameTime) {
70
+ if (auto reanimatedModule = weakReanimatedModule.lock()) {
71
+ onRender(frameTime);
72
+ }
73
+ });
74
+ };
75
+
76
+ auto progressLayoutAnimation = [=](jsi::Runtime &rt, int tag, const jsi::Object &newStyle,
77
+ bool isSharedTransition) {
78
+ // noop
79
+ };
80
+
81
+ auto endLayoutAnimation = [=](int tag, bool removeView) {
82
+ // noop
83
+ };
84
+
85
+ auto getAnimationTimestamp = getMillisSinceEpoch;
86
+
87
+ auto registerSensorFunction = [](int sensorType, int interval, int iosReferenceFrame,
88
+ std::function<void(double[], int)> setter) -> int {
89
+ // TODO
90
+ return -1;
91
+ };
92
+ auto unregisterSensorFunction = [](int sensorId) {
93
+ // TODO
94
+ };
95
+ auto subscribeForKeyboardEventsFunction =
96
+ [weakSelf = weak_from_this()](std::function<void(int keyboardState, int height)> keyboardEventDataUpdater,
97
+ bool isStatusBarTranslucent, bool isNavigationBarTranslucent) {
98
+ auto self = weakSelf.lock();
99
+ if (!self) {
100
+ return 0;
101
+ }
102
+ self->keyboardEventDataUpdater_ = std::move(keyboardEventDataUpdater);
103
+ auto weakExecutor = std::weak_ptr(self->m_ctx.taskExecutor);
104
+ if (auto taskExecutor = weakExecutor.lock()) {
105
+ taskExecutor->runTask(TaskThread::MAIN, [ctx = self->m_ctx, isStatusBarTranslucent]() {
106
+ ArkJS arkJs(ctx.env);
107
+ // arkJs.createBoolean(isStatusBarTranslucent);
108
+ auto napiTurboModuleObject = arkJs.getObject(ctx.arkTSTurboModuleInstanceRef);
109
+ napiTurboModuleObject.call("subscribeKeyBordListeners", {});
110
+ });
111
+ }
112
+ return 0;
113
+ };
114
+ auto unsubscribeFromKeyboardEventsFunction = [weakSelf = weak_from_this()](int listenerId) {
115
+ auto self = weakSelf.lock();
116
+ if (!self) {
117
+ return 0;
118
+ }
119
+ auto weakExecutor = std::weak_ptr(self->m_ctx.taskExecutor);
120
+ if (auto taskExecutor = weakExecutor.lock()) {
121
+ taskExecutor->runTask(TaskThread::MAIN, [ctx = self->m_ctx]() {
122
+ ArkJS arkJs(ctx.env);
123
+ auto napiTurboModuleObject = arkJs.getObject(ctx.arkTSTurboModuleInstanceRef);
124
+ napiTurboModuleObject.call("unsubscribeKeyBordListeners", {});
125
+ });
126
+ }
127
+ return 0;
128
+ };
129
+ auto setGestureStateFunction = [weakSelf = weak_from_this()](int handlerTag, int newState) {
130
+ auto self = weakSelf.lock();
131
+ if (!self) {
132
+ return;
133
+ }
134
+ ArkJS arkJs(self->m_ctx.env);
135
+ auto napiTag = arkJs.createInt(handlerTag);
136
+ auto napiState = arkJs.createInt(newState);
137
+ auto napiTurboModuleObject = arkJs.getObject(self->m_ctx.arkTSTurboModuleInstanceRef);
138
+ napiTurboModuleObject.call("setGestureHandlerState", { napiTag, napiState });
139
+ };
140
+ PlatformDepMethodsHolder platformDepMethodsHolder = {
141
+ requestRender,
142
+ getAnimationTimestamp,
143
+ progressLayoutAnimation,
144
+ endLayoutAnimation,
145
+ registerSensorFunction,
146
+ unregisterSensorFunction,
147
+ setGestureStateFunction,
148
+ subscribeForKeyboardEventsFunction,
149
+ unsubscribeFromKeyboardEventsFunction,
150
+ maybeFlushUIUpdatesQueueFunction,
151
+ };
152
+ auto isReducedMotion = false;
153
+ auto isBridgeless = true;
154
+ auto workletsModule = [weakSelf = weak_from_this()]() -> std::shared_ptr<WorkletsModule> {
155
+ auto self = weakSelf.lock();
156
+ if (!self) {
157
+ return nullptr;
158
+ }
159
+ auto instance = self->m_ctx.instance.lock();
160
+ if (instance == nullptr) {
161
+ return nullptr;
162
+ }
163
+ return instance->getTurboModule<WorkletsModule>("WorkletsModule");
164
+ };
165
+ auto nativeReanimatedModule = std::make_shared<ReanimatedModuleProxy>(workletsModule()->getWorkletsModuleProxy(),
166
+ rt, jsInvoker_, platformDepMethodsHolder, isBridgeless, isReducedMotion);
167
+ weakNativeReanimatedModule_ = nativeReanimatedModule;
168
+ nativeReanimatedModule->init(platformDepMethodsHolder);
169
+ ReanimatedPerformOperations reanimatedPerformOperations = [weakNativeReanimatedModule =
170
+ weakNativeReanimatedModule_]() {
171
+ if (auto nativeReanimatedModule = weakNativeReanimatedModule.lock()) {
172
+ nativeReanimatedModule->performOperations();
173
+ }
174
+ };
175
+ nodesManager->registerPerformOperations(reanimatedPerformOperations);
176
+
177
+ WorkletRuntimeCollector::install(rt);
178
+
179
+ RNRuntimeDecorator::decorate(rt, nativeReanimatedModule);
180
+ injectDependencies(rt);
181
+
182
+ eventListener =
183
+ std::make_shared<facebook::react::EventListener>([weakNativeReanimatedModule = weakNativeReanimatedModule_,
184
+ weakTaskExecutor = std::weak_ptr{ m_ctx.taskExecutor }](facebook::react::RawEvent const & rawEvent) {
185
+ auto taskExecutor = weakTaskExecutor.lock();
186
+ auto nativeReanimatedModule = weakNativeReanimatedModule.lock();
187
+ if (!nativeReanimatedModule || !taskExecutor || !taskExecutor->isOnTaskThread(TaskThread::MAIN)) {
188
+ return false;
189
+ }
190
+
191
+ auto eventType = rawEvent.type;
192
+ auto frameTime = getMillisSinceEpoch();
193
+
194
+ // React Native prefixes event names with "top". If the event name starts with "on", the result is that the
195
+ // event on the native side is prefixed with "topOn", while the JS side expects the event name to be without
196
+ // the "on" prefix.
197
+ if (eventType.rfind("topOn", 0) == 0) {
198
+ auto eventCopy = rawEvent;
199
+ eventCopy.type = "on" + eventType.substr(5);
200
+ return nativeReanimatedModule->handleRawEvent(eventCopy, frameTime);
201
+ } else if (eventType.rfind("topLayout", 0) == 0) { // 针对onLayout事件,不阻断,采用系统处理
202
+ return false;
203
+ }
204
+ return nativeReanimatedModule->handleRawEvent(rawEvent, frameTime);
205
+ });
206
+ m_ctx.scheduler->addEventListener(eventListener);
207
+ }
208
+ void ReanimatedModule::injectDependencies(facebook::jsi::Runtime & /* rt */)
209
+ {
210
+ const auto uiManager = m_ctx.scheduler->getUIManager();
211
+ if (auto nativeReanimatedModule = weakNativeReanimatedModule_.lock()) {
212
+ nativeReanimatedModule->initializeFabric(uiManager);
213
+ }
214
+ }
215
+
216
+ void ReanimatedModule::callKeyBord(double height, int status)
217
+ {
218
+ if (keyboardEventDataUpdater_) {
219
+ keyboardEventDataUpdater_(status, height);
220
+ }
221
+ }
222
+ } // namespace rnoh
@@ -0,0 +1,24 @@
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 "ReanimatedModuleProxy.h"
9
+ #include "ReanimatedNodesManager.h"
10
+
11
+ namespace rnoh {
12
+ class JSI_EXPORT ReanimatedModule : public std::enable_shared_from_this<ReanimatedModule>, public ArkTSTurboModule {
13
+ public:
14
+ ReanimatedModule(const ArkTSTurboModule::Context ctx, const std::string name);
15
+ ~ReanimatedModule() override;
16
+ void installTurboModule(facebook::jsi::Runtime &rt);
17
+ void callKeyBord(double height, int status);
18
+ private:
19
+ std::weak_ptr<reanimated::ReanimatedModuleProxy> weakNativeReanimatedModule_;
20
+ void injectDependencies(facebook::jsi::Runtime &rt);
21
+ std::shared_ptr<facebook::react::EventListener> eventListener;
22
+ std::function<void(int keyboardState, int height)> keyboardEventDataUpdater_;
23
+ };
24
+ } // namespace rnoh
@@ -0,0 +1,56 @@
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 "ReanimatedNodesManager.h"
6
+
7
+ constexpr int64_t NANO_TO_MILLIS = 1000000;
8
+
9
+ namespace rnoh {
10
+ static void vsyncHandleCallback(long long timestamp, void *data)
11
+ {
12
+ auto self = static_cast<ReanimatedNodesManager *>(data);
13
+ self->onAnimationFrame(timestamp);
14
+ }
15
+ ReanimatedNodesManager::ReanimatedNodesManager(std::function<void(TaskExecutor::Task &&)> runOnTheMainThread)
16
+ : m_vsyncHandle("ReanimatedNodesManager"), runOnTheMainThread(std::move(runOnTheMainThread))
17
+ {}
18
+
19
+ void ReanimatedNodesManager::maybeFlushUIUpdatesQueue()
20
+ {
21
+ performOperations();
22
+ };
23
+
24
+ void ReanimatedNodesManager::registerPerformOperations(ReanimatedPerformOperations reanimatedPerformOperations)
25
+ {
26
+ performOperations = std::move(reanimatedPerformOperations);
27
+ }
28
+
29
+ void ReanimatedNodesManager::postOnAnimation(ReanimatedOnAnimationCallback callback)
30
+ {
31
+ onAnimationCallbacks.push_back(std::move(callback));
32
+ m_vsyncHandle.requestFrame(vsyncHandleCallback, this);
33
+ }
34
+
35
+ void ReanimatedNodesManager::operationBatchDidComplete()
36
+ {
37
+ performOperations();
38
+ }
39
+
40
+ void ReanimatedNodesManager::onAnimationFrame(int64_t timestamp)
41
+ {
42
+ runOnTheMainThread([weakSelf = weak_from_this(), timestamp]() {
43
+ auto self = weakSelf.lock();
44
+ if (!self) {
45
+ return;
46
+ }
47
+ std::vector<ReanimatedOnAnimationCallback> callbacks;
48
+ std::swap(callbacks, self->onAnimationCallbacks);
49
+
50
+ for (auto &callback : callbacks) {
51
+ callback(timestamp / NANO_TO_MILLIS);
52
+ }
53
+ self->performOperations();
54
+ });
55
+ }
56
+ } // namespace rnoh