@react-native-ohos/react-native-reanimated 3.18.2 → 3.18.3

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 (99) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +406 -10
  4. package/harmony/reanimated/BuildProfile.ets +1 -1
  5. package/harmony/reanimated/build-profile.json5 +11 -11
  6. package/harmony/reanimated/oh-package-lock.json5 +29 -0
  7. package/harmony/reanimated/oh-package.json5 +11 -11
  8. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +2 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +73 -68
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -96
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -254
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -173
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -189
  81. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  82. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +29 -19
  83. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +248 -0
  84. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +36 -0
  85. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +36 -0
  86. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +23 -0
  87. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
  88. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  89. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +53 -4
  90. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +115 -15
  91. package/harmony/reanimated/src/main/module.json5 +12 -12
  92. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  93. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  94. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  95. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  96. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  97. package/harmony/reanimated/ts.ts +6 -6
  98. package/harmony/reanimated.har +0 -0
  99. package/package.json +51 -50
@@ -1,189 +1,189 @@
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
- if (hostFunValue.isUndefined() || !hostFunValue.isObject()) {
141
- return;
142
- }
143
- auto hostFunObject = hostFunValue.asObject(rt);
144
- if (!hostFunObject.isFunction(rt) || !hostFunObject.asFunction(rt).isHostFunction(rt)) {
145
- return;
146
- }
147
- auto hostFun =
148
- hostFunObject.asFunction(rt).getHostFunction(rt);
149
-
150
- auto shareableArgs = argsValue.isUndefined()
151
- ? nullptr
152
- : extractShareableOrThrow<ShareableArray>(
153
- rt, argsValue, "[Reanimated] Args must be an array.");
154
-
155
- jsScheduler->scheduleOnJS([=](jsi::Runtime &rt) {
156
- auto args = parseArgs(rt, shareableArgs);
157
- hostFun(
158
- rt,
159
- jsi::Value::undefined(),
160
- const_cast<const jsi::Value *>(args.data()),
161
- args.size());
162
- });
163
- });
164
-
165
- jsi_utils::installJsiFunction(
166
- rt,
167
- "_scheduleOnRuntime",
168
- [](jsi::Runtime &rt,
169
- const jsi::Value &workletRuntimeValue,
170
- const jsi::Value &shareableWorkletValue) {
171
- scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
172
- });
173
-
174
- jsi::Object performance(rt);
175
- performance.setProperty(
176
- rt,
177
- "now",
178
- jsi::Function::createFromHostFunction(
179
- rt,
180
- jsi::PropNameID::forAscii(rt, "now"),
181
- 0,
182
- [](jsi::Runtime &runtime,
183
- const jsi::Value &,
184
- const jsi::Value *args,
185
- size_t count) { return jsi::Value(performanceNow()); }));
186
- rt.global().setProperty(rt, "performance", performance);
187
- }
188
-
189
- } // 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
+ if (hostFunValue.isUndefined() || !hostFunValue.isObject()) {
141
+ return;
142
+ }
143
+ auto hostFunObject = hostFunValue.asObject(rt);
144
+ if (!hostFunObject.isFunction(rt) || !hostFunObject.asFunction(rt).isHostFunction(rt)) {
145
+ return;
146
+ }
147
+ auto hostFun =
148
+ hostFunObject.asFunction(rt).getHostFunction(rt);
149
+
150
+ auto shareableArgs = argsValue.isUndefined()
151
+ ? nullptr
152
+ : extractShareableOrThrow<ShareableArray>(
153
+ rt, argsValue, "[Reanimated] Args must be an array.");
154
+
155
+ jsScheduler->scheduleOnJS([=](jsi::Runtime &rt) {
156
+ auto args = parseArgs(rt, shareableArgs);
157
+ hostFun(
158
+ rt,
159
+ jsi::Value::undefined(),
160
+ const_cast<const jsi::Value *>(args.data()),
161
+ args.size());
162
+ });
163
+ });
164
+
165
+ jsi_utils::installJsiFunction(
166
+ rt,
167
+ "_scheduleOnRuntime",
168
+ [](jsi::Runtime &rt,
169
+ const jsi::Value &workletRuntimeValue,
170
+ const jsi::Value &shareableWorkletValue) {
171
+ scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
172
+ });
173
+
174
+ jsi::Object performance(rt);
175
+ performance.setProperty(
176
+ rt,
177
+ "now",
178
+ jsi::Function::createFromHostFunction(
179
+ rt,
180
+ jsi::PropNameID::forAscii(rt, "now"),
181
+ 0,
182
+ [](jsi::Runtime &runtime,
183
+ const jsi::Value &,
184
+ const jsi::Value *args,
185
+ size_t count) { return jsi::Value(performanceNow()); }));
186
+ rt.global().setProperty(rt, "performance", performance);
187
+ }
188
+
189
+ } // 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
@@ -5,6 +5,7 @@
5
5
  #include "RNOH/ArkTSTurboModule.h"
6
6
  #include "RNOH/RNInstance.h"
7
7
  #include "ReanimatedModule.h"
8
+ #include "ReanimatedSensorContainer.h"
8
9
  #include "ReanimatedUIScheduler.h"
9
10
  #include "PlatformDepMethodsHolder.h"
10
11
  #include "WorkletRuntimeCollector.h"
@@ -50,19 +51,16 @@ ReanimatedModule::~ReanimatedModule()
50
51
  if (keyboardEventDataUpdater_) {
51
52
  keyboardEventDataUpdater_ = nullptr;
52
53
  }
53
- if (auto nativeReanimatedModule = weakNativeReanimatedModule_.lock()) {
54
- nativeReanimatedModule->invalidate();
55
- }
56
54
  }
57
55
 
58
56
  void ReanimatedModule::installTurboModule(facebook::jsi::Runtime &rt)
59
57
  {
60
- auto nodesManager = std::make_shared<ReanimatedNodesManager>(
61
- [weakExecutor = std::weak_ptr(m_ctx.taskExecutor)](TaskExecutor::Task &&task) {
62
- if (auto taskExecutor = weakExecutor.lock()) {
63
- taskExecutor->runTask(TaskThread::MAIN, std::move(task));
64
- }
65
- });
58
+ auto runMainThreadFuc = [weakExecutor = std::weak_ptr(m_ctx.taskExecutor)](TaskExecutor::Task &&task) {
59
+ if (auto taskExecutor = weakExecutor.lock()) {
60
+ taskExecutor->runTask(TaskThread::MAIN, std::move(task));
61
+ }
62
+ };
63
+ auto nodesManager = std::make_shared<ReanimatedNodesManager>(runMainThreadFuc);
66
64
 
67
65
  auto maybeFlushUIUpdatesQueueFunction = [nodesManager]() { nodesManager->maybeFlushUIUpdatesQueue(); };
68
66
  auto requestRender = [weakSelf = weak_from_this(), nodesManager](std::function<void(double)> onRender) {
@@ -90,14 +88,13 @@ void ReanimatedModule::installTurboModule(facebook::jsi::Runtime &rt)
90
88
 
91
89
  auto getAnimationTimestamp = getMillisSinceEpoch;
92
90
 
93
- auto registerSensorFunction = [](int sensorType, int interval, int iosReferenceFrame,
91
+ auto sensorContainer = std::make_shared<ReanimatedSensorContainer>();
92
+ auto registerSensorFunction = [sensorContainer,
93
+ runMainThreadFuc](int sensorType, int interval, int iosReferenceFrame,
94
94
  std::function<void(double[], int)> setter) -> int {
95
- // TODO
96
- return -1;
97
- };
98
- auto unregisterSensorFunction = [](int sensorId) {
99
- // TODO
95
+ return sensorContainer->registerSensor(sensorType, interval, iosReferenceFrame, setter, runMainThreadFuc);
100
96
  };
97
+ auto unregisterSensorFunction = [sensorContainer](int sensorId) { sensorContainer->unregisterSensor(sensorId); };
101
98
  auto subscribeForKeyboardEventsFunction =
102
99
  [weakSelf = weak_from_this()](std::function<void(int keyboardState, int height)> keyboardEventDataUpdater,
103
100
  bool isStatusBarTranslucent, bool isNavigationBarTranslucent) {
@@ -108,11 +105,12 @@ void ReanimatedModule::installTurboModule(facebook::jsi::Runtime &rt)
108
105
  self->keyboardEventDataUpdater_ = std::move(keyboardEventDataUpdater);
109
106
  auto weakExecutor = std::weak_ptr(self->m_ctx.taskExecutor);
110
107
  if (auto taskExecutor = weakExecutor.lock()) {
111
- taskExecutor->runTask(TaskThread::MAIN, [ctx = self->m_ctx, isStatusBarTranslucent]() {
108
+ taskExecutor->runTask(TaskThread::MAIN, [ctx = self->m_ctx, isStatusBarTranslucent, isNavigationBarTranslucent]() {
112
109
  ArkJS arkJs(ctx.env);
113
- // arkJs.createBoolean(isStatusBarTranslucent);
110
+ auto isStatusBarTranslucentValue = arkJs.createBoolean(isStatusBarTranslucent);
111
+ auto isNavigationBarTranslucentValue = arkJs.createBoolean(isNavigationBarTranslucent);
114
112
  auto napiTurboModuleObject = arkJs.getObject(ctx.arkTSTurboModuleInstanceRef);
115
- napiTurboModuleObject.call("subscribeKeyBordListeners", {});
113
+ napiTurboModuleObject.call("subscribeKeyBordListeners", {isStatusBarTranslucentValue, isNavigationBarTranslucentValue});
116
114
  });
117
115
  }
118
116
  return 0;
@@ -155,7 +153,19 @@ void ReanimatedModule::installTurboModule(facebook::jsi::Runtime &rt)
155
153
  unsubscribeFromKeyboardEventsFunction,
156
154
  maybeFlushUIUpdatesQueueFunction,
157
155
  };
158
- auto isReducedMotion = false;
156
+ bool isReducedMotion = false;
157
+ m_ctx.taskExecutor->runSyncTask(TaskThread::MAIN,
158
+ [ctx = m_ctx, &isReducedMotion]() {
159
+ if (!ctx.arkTSTurboModuleInstanceRef) {
160
+ return;
161
+ }
162
+ ArkJS arkJs(ctx.env);
163
+ auto napiTurboModuleObject =
164
+ arkJs.getObject(ctx.arkTSTurboModuleInstanceRef);
165
+ auto napiResult =
166
+ napiTurboModuleObject.call("isReducedMotionEnabled", {});
167
+ isReducedMotion = arkJs.getBoolean(napiResult);
168
+ });
159
169
  auto isBridgeless = true;
160
170
  auto workletsModule = [weakSelf = weak_from_this()]() -> std::shared_ptr<WorkletsModule> {
161
171
  auto self = weakSelf.lock();