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

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +10 -0
  4. package/harmony/reanimated/BuildProfile.ets +16 -16
  5. package/harmony/reanimated/build-profile.json5 +11 -11
  6. package/harmony/reanimated/oh-package.json5 +11 -11
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -68
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +87 -87
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -252
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +155 -155
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +182 -182
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  80. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +57 -57
  81. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  82. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +3 -0
  83. package/harmony/reanimated/src/main/module.json5 +12 -12
  84. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  85. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  86. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  87. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  88. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  89. package/harmony/reanimated/ts.ts +6 -6
  90. package/harmony/reanimated.har +0 -0
  91. package/package.json +50 -50
@@ -1,182 +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
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
@@ -1,22 +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
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
@@ -1,58 +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
- }
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
58
  } // namespace worklets