@react-native-ohos/react-native-reanimated 3.18.2-rc.2 → 3.18.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 (92) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +10 -10
  4. package/harmony/reanimated/BuildProfile.ets +1 -1
  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 +96 -96
  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 +254 -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 +173 -173
  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 +189 -189
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  80. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +3 -0
  81. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
  82. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  83. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +4 -0
  84. package/harmony/reanimated/src/main/module.json5 +12 -12
  85. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  86. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  87. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  88. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  89. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  90. package/harmony/reanimated/ts.ts +6 -6
  91. package/harmony/reanimated.har +0 -0
  92. package/package.json +50 -50
@@ -1,173 +1,173 @@
1
- #include <worklets/Tools/JSISerializer.h>
2
- #include <worklets/Tools/PlatformLogger.h>
3
- #include <worklets/WorkletRuntime/ReanimatedRuntime.h>
4
- #include <worklets/WorkletRuntime/WorkletRuntime.h>
5
- #include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
6
- #include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
7
-
8
- #include <jsi/decorator.h>
9
-
10
- namespace worklets {
11
-
12
- class AroundLock {
13
- const std::shared_ptr<std::recursive_mutex> mutex_;
14
-
15
- public:
16
- explicit AroundLock(const std::shared_ptr<std::recursive_mutex> &mutex)
17
- : mutex_(mutex) {}
18
-
19
- void before() const {
20
- mutex_->lock();
21
- }
22
-
23
- void after() const {
24
- mutex_->unlock();
25
- }
26
- };
27
-
28
- class LockableRuntime : public jsi::WithRuntimeDecorator<AroundLock> {
29
- AroundLock aroundLock_;
30
- std::shared_ptr<jsi::Runtime> runtime_;
31
-
32
- public:
33
- explicit LockableRuntime(
34
- std::shared_ptr<jsi::Runtime> &runtime,
35
- const std::shared_ptr<std::recursive_mutex> &runtimeMutex)
36
- : jsi::WithRuntimeDecorator<AroundLock>(*runtime, aroundLock_),
37
- aroundLock_(runtimeMutex),
38
- runtime_(std::move(runtime)) {}
39
- };
40
-
41
- static std::shared_ptr<jsi::Runtime> makeRuntime(
42
- jsi::Runtime &runtime,
43
- const std::shared_ptr<MessageQueueThread> &jsQueue,
44
- const std::string &name,
45
- const bool supportsLocking,
46
- const std::shared_ptr<std::recursive_mutex> &runtimeMutex) {
47
- auto reanimatedRuntime = ReanimatedRuntime::make(runtime, jsQueue, name);
48
- if (supportsLocking) {
49
- return std::make_shared<LockableRuntime>(reanimatedRuntime, runtimeMutex);
50
- } else {
51
- return reanimatedRuntime;
52
- }
53
- }
54
-
55
- WorkletRuntime::WorkletRuntime(
56
- jsi::Runtime &rnRuntime,
57
- const std::shared_ptr<MessageQueueThread> &jsQueue,
58
- const std::shared_ptr<JSScheduler> &jsScheduler,
59
- const std::string &name,
60
- const bool supportsLocking,
61
- const std::string &valueUnpackerCode)
62
- : runtimeMutex_(std::make_shared<std::recursive_mutex>()),
63
- runtime_(makeRuntime(
64
- rnRuntime,
65
- jsQueue,
66
- name,
67
- supportsLocking,
68
- runtimeMutex_)),
69
- #ifndef NDEBUG
70
- supportsLocking_(supportsLocking),
71
- #endif
72
- name_(name) {
73
- jsi::Runtime &rt = *runtime_;
74
- WorkletRuntimeCollector::install(rt);
75
- WorkletRuntimeDecorator::decorate(rt, name, jsScheduler);
76
-
77
- auto codeBuffer = std::make_shared<const jsi::StringBuffer>(
78
- "(" + valueUnpackerCode + "\n)");
79
- auto valueUnpacker = rt.evaluateJavaScript(codeBuffer, "valueUnpacker")
80
- .asObject(rt)
81
- .asFunction(rt);
82
- rt.global().setProperty(rt, "__valueUnpacker", valueUnpacker);
83
- }
84
-
85
- jsi::Value WorkletRuntime::executeSync(
86
- jsi::Runtime &rt,
87
- const jsi::Value &worklet) const {
88
- if (worklet.isNull() || worklet.isUndefined()) {
89
- PlatformLogger::log('worklet isNull or isUndefined');
90
- return jsi::Value::undefined();
91
- }
92
-
93
- assert(
94
- supportsLocking_ &&
95
- ("[Reanimated] Runtime \"" + name_ + "\" doesn't support locking.")
96
- .c_str());
97
-
98
- auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
99
- rt,
100
- worklet,
101
- "[Reanimated] Only worklets can be executed synchronously on UI runtime.");
102
-
103
- if (!shareableWorklet) {
104
- PlatformLogger::log('shareableWorklet is undefined');
105
- return jsi::Value::undefined();
106
- }
107
-
108
- auto lock = std::unique_lock<std::recursive_mutex>(*runtimeMutex_);
109
- jsi::Runtime &uiRuntime = getJSIRuntime();
110
- auto result = runGuarded(shareableWorklet);
111
- auto shareableResult = extractShareableOrThrow(uiRuntime, result);
112
- lock.unlock();
113
-
114
- if (shareableResult && !shareableResult->toJSValue(rt).isNull()) {
115
- return shareableResult->toJSValue(rt);
116
- }
117
- PlatformLogger::log('shareableResult is undefined');
118
- return jsi::Value::undefined();
119
- }
120
-
121
- jsi::Value WorkletRuntime::get(
122
- jsi::Runtime &rt,
123
- const jsi::PropNameID &propName) {
124
- auto name = propName.utf8(rt);
125
- if (name == "toString") {
126
- return jsi::Function::createFromHostFunction(
127
- rt,
128
- propName,
129
- 0,
130
- [weakThis = weak_from_this()](
131
- jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t)
132
- -> jsi::Value {
133
- auto strongThis = weakThis.lock();
134
- if (!strongThis) {
135
- return jsi::String::createFromUtf8(rt, "");
136
- }
137
-
138
- return jsi::String::createFromUtf8(rt, strongThis->toString());
139
- });
140
- }
141
- if (name == "name") {
142
- return jsi::String::createFromUtf8(rt, name_);
143
- }
144
- return jsi::Value::undefined();
145
- }
146
-
147
- std::vector<jsi::PropNameID> WorkletRuntime::getPropertyNames(
148
- jsi::Runtime &rt) {
149
- std::vector<jsi::PropNameID> result;
150
- result.push_back(jsi::PropNameID::forUtf8(rt, "toString"));
151
- result.push_back(jsi::PropNameID::forUtf8(rt, "name"));
152
- return result;
153
- }
154
-
155
- std::shared_ptr<WorkletRuntime> extractWorkletRuntime(
156
- jsi::Runtime &rt,
157
- const jsi::Value &value) {
158
- return value.getObject(rt).getHostObject<WorkletRuntime>(rt);
159
- }
160
-
161
- void scheduleOnRuntime(
162
- jsi::Runtime &rt,
163
- const jsi::Value &workletRuntimeValue,
164
- const jsi::Value &shareableWorkletValue) {
165
- auto workletRuntime = extractWorkletRuntime(rt, workletRuntimeValue);
166
- auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
167
- rt,
168
- shareableWorkletValue,
169
- "[Reanimated] Function passed to `_scheduleOnRuntime` is not a shareable worklet. Please make sure that `processNestedWorklets` option in Reanimated Babel plugin is enabled.");
170
- workletRuntime->runAsyncGuarded(shareableWorklet);
171
- }
172
-
173
- } // namespace worklets
1
+ #include <worklets/Tools/JSISerializer.h>
2
+ #include <worklets/Tools/PlatformLogger.h>
3
+ #include <worklets/WorkletRuntime/ReanimatedRuntime.h>
4
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
5
+ #include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
6
+ #include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
7
+
8
+ #include <jsi/decorator.h>
9
+
10
+ namespace worklets {
11
+
12
+ class AroundLock {
13
+ const std::shared_ptr<std::recursive_mutex> mutex_;
14
+
15
+ public:
16
+ explicit AroundLock(const std::shared_ptr<std::recursive_mutex> &mutex)
17
+ : mutex_(mutex) {}
18
+
19
+ void before() const {
20
+ mutex_->lock();
21
+ }
22
+
23
+ void after() const {
24
+ mutex_->unlock();
25
+ }
26
+ };
27
+
28
+ class LockableRuntime : public jsi::WithRuntimeDecorator<AroundLock> {
29
+ AroundLock aroundLock_;
30
+ std::shared_ptr<jsi::Runtime> runtime_;
31
+
32
+ public:
33
+ explicit LockableRuntime(
34
+ std::shared_ptr<jsi::Runtime> &runtime,
35
+ const std::shared_ptr<std::recursive_mutex> &runtimeMutex)
36
+ : jsi::WithRuntimeDecorator<AroundLock>(*runtime, aroundLock_),
37
+ aroundLock_(runtimeMutex),
38
+ runtime_(std::move(runtime)) {}
39
+ };
40
+
41
+ static std::shared_ptr<jsi::Runtime> makeRuntime(
42
+ jsi::Runtime &runtime,
43
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
44
+ const std::string &name,
45
+ const bool supportsLocking,
46
+ const std::shared_ptr<std::recursive_mutex> &runtimeMutex) {
47
+ auto reanimatedRuntime = ReanimatedRuntime::make(runtime, jsQueue, name);
48
+ if (supportsLocking) {
49
+ return std::make_shared<LockableRuntime>(reanimatedRuntime, runtimeMutex);
50
+ } else {
51
+ return reanimatedRuntime;
52
+ }
53
+ }
54
+
55
+ WorkletRuntime::WorkletRuntime(
56
+ jsi::Runtime &rnRuntime,
57
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
58
+ const std::shared_ptr<JSScheduler> &jsScheduler,
59
+ const std::string &name,
60
+ const bool supportsLocking,
61
+ const std::string &valueUnpackerCode)
62
+ : runtimeMutex_(std::make_shared<std::recursive_mutex>()),
63
+ runtime_(makeRuntime(
64
+ rnRuntime,
65
+ jsQueue,
66
+ name,
67
+ supportsLocking,
68
+ runtimeMutex_)),
69
+ #ifndef NDEBUG
70
+ supportsLocking_(supportsLocking),
71
+ #endif
72
+ name_(name) {
73
+ jsi::Runtime &rt = *runtime_;
74
+ WorkletRuntimeCollector::install(rt);
75
+ WorkletRuntimeDecorator::decorate(rt, name, jsScheduler);
76
+
77
+ auto codeBuffer = std::make_shared<const jsi::StringBuffer>(
78
+ "(" + valueUnpackerCode + "\n)");
79
+ auto valueUnpacker = rt.evaluateJavaScript(codeBuffer, "valueUnpacker")
80
+ .asObject(rt)
81
+ .asFunction(rt);
82
+ rt.global().setProperty(rt, "__valueUnpacker", valueUnpacker);
83
+ }
84
+
85
+ jsi::Value WorkletRuntime::executeSync(
86
+ jsi::Runtime &rt,
87
+ const jsi::Value &worklet) const {
88
+ if (worklet.isNull() || worklet.isUndefined()) {
89
+ PlatformLogger::log('worklet isNull or isUndefined');
90
+ return jsi::Value::undefined();
91
+ }
92
+
93
+ assert(
94
+ supportsLocking_ &&
95
+ ("[Reanimated] Runtime \"" + name_ + "\" doesn't support locking.")
96
+ .c_str());
97
+
98
+ auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
99
+ rt,
100
+ worklet,
101
+ "[Reanimated] Only worklets can be executed synchronously on UI runtime.");
102
+
103
+ if (!shareableWorklet) {
104
+ PlatformLogger::log('shareableWorklet is undefined');
105
+ return jsi::Value::undefined();
106
+ }
107
+
108
+ auto lock = std::unique_lock<std::recursive_mutex>(*runtimeMutex_);
109
+ jsi::Runtime &uiRuntime = getJSIRuntime();
110
+ auto result = runGuarded(shareableWorklet);
111
+ auto shareableResult = extractShareableOrThrow(uiRuntime, result);
112
+ lock.unlock();
113
+
114
+ if (shareableResult && !shareableResult->toJSValue(rt).isNull()) {
115
+ return shareableResult->toJSValue(rt);
116
+ }
117
+ PlatformLogger::log('shareableResult is undefined');
118
+ return jsi::Value::undefined();
119
+ }
120
+
121
+ jsi::Value WorkletRuntime::get(
122
+ jsi::Runtime &rt,
123
+ const jsi::PropNameID &propName) {
124
+ auto name = propName.utf8(rt);
125
+ if (name == "toString") {
126
+ return jsi::Function::createFromHostFunction(
127
+ rt,
128
+ propName,
129
+ 0,
130
+ [weakThis = weak_from_this()](
131
+ jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t)
132
+ -> jsi::Value {
133
+ auto strongThis = weakThis.lock();
134
+ if (!strongThis) {
135
+ return jsi::String::createFromUtf8(rt, "");
136
+ }
137
+
138
+ return jsi::String::createFromUtf8(rt, strongThis->toString());
139
+ });
140
+ }
141
+ if (name == "name") {
142
+ return jsi::String::createFromUtf8(rt, name_);
143
+ }
144
+ return jsi::Value::undefined();
145
+ }
146
+
147
+ std::vector<jsi::PropNameID> WorkletRuntime::getPropertyNames(
148
+ jsi::Runtime &rt) {
149
+ std::vector<jsi::PropNameID> result;
150
+ result.push_back(jsi::PropNameID::forUtf8(rt, "toString"));
151
+ result.push_back(jsi::PropNameID::forUtf8(rt, "name"));
152
+ return result;
153
+ }
154
+
155
+ std::shared_ptr<WorkletRuntime> extractWorkletRuntime(
156
+ jsi::Runtime &rt,
157
+ const jsi::Value &value) {
158
+ return value.getObject(rt).getHostObject<WorkletRuntime>(rt);
159
+ }
160
+
161
+ void scheduleOnRuntime(
162
+ jsi::Runtime &rt,
163
+ const jsi::Value &workletRuntimeValue,
164
+ const jsi::Value &shareableWorkletValue) {
165
+ auto workletRuntime = extractWorkletRuntime(rt, workletRuntimeValue);
166
+ auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
167
+ rt,
168
+ shareableWorkletValue,
169
+ "[Reanimated] Function passed to `_scheduleOnRuntime` is not a shareable worklet. Please make sure that `processNestedWorklets` option in Reanimated Babel plugin is enabled.");
170
+ workletRuntime->runAsyncGuarded(shareableWorklet);
171
+ }
172
+
173
+ } // namespace worklets
@@ -1,90 +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
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
@@ -1,36 +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
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