react-native-worklets 0.3.0 → 0.4.0-nightly-20250521-922379cf5

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.
@@ -0,0 +1,288 @@
1
+ #include <react/renderer/uimanager/UIManagerBinding.h>
2
+ #include <react/renderer/uimanager/primitives.h>
3
+
4
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
5
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
6
+ #include <worklets/SharedItems/Shareables.h>
7
+ #include <worklets/Tools/Defs.h>
8
+ #include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
9
+
10
+ #ifdef __ANDROID__
11
+ #include <fbjni/fbjni.h>
12
+ #endif // __ANDROID__
13
+
14
+ #include <string>
15
+ #include <utility>
16
+
17
+ using namespace facebook;
18
+
19
+ namespace worklets {
20
+
21
+ inline void scheduleOnUI(
22
+ const std::shared_ptr<UIScheduler> &uiScheduler,
23
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
24
+ jsi::Runtime &rt,
25
+ const jsi::Value &worklet) {
26
+ auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
27
+ rt, worklet, "[Worklets] Only worklets can be scheduled to run on UI.");
28
+ uiScheduler->scheduleOnUI([shareableWorklet, weakUIWorkletRuntime]() {
29
+ // This callback can outlive the WorkletsModuleProxy object during the
30
+ // invalidation of React Native. This happens when WorkletsModuleProxy
31
+ // destructor is called on the JS thread and the UI thread is
32
+ // executing callbacks from the `scheduleOnUI` queue. Therefore, we
33
+ // need to make sure it's still alive before we try to access it.
34
+ auto uiWorkletRuntime = weakUIWorkletRuntime.lock();
35
+ if (!uiWorkletRuntime) {
36
+ return;
37
+ }
38
+
39
+ #if JS_RUNTIME_HERMES
40
+ // JSI's scope defined here allows for JSI-objects to be cleared up
41
+ // after each runtime loop. Within these loops we typically create
42
+ // some temporary JSI objects and hence it allows for such objects to
43
+ // be garbage collected much sooner. Apparently the scope API is only
44
+ // supported on Hermes at the moment.
45
+ const auto scope = jsi::Scope(uiWorkletRuntime->getJSIRuntime());
46
+ #endif // JS_RUNTIME_HERMES
47
+
48
+ uiWorkletRuntime->runGuarded(shareableWorklet);
49
+ });
50
+ }
51
+
52
+ inline jsi::Value executeOnUIRuntimeSync(
53
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
54
+ jsi::Runtime &rt,
55
+ const jsi::Value &worklet) {
56
+ if (auto uiWorkletRuntime = weakUIWorkletRuntime.lock()) {
57
+ return uiWorkletRuntime->executeSync(rt, worklet);
58
+ }
59
+ return jsi::Value::undefined();
60
+ }
61
+
62
+ inline jsi::Value createWorkletRuntime(
63
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
64
+ const std::shared_ptr<JSScheduler> &jsScheduler,
65
+ std::shared_ptr<JSIWorkletsModuleProxy> jsiWorkletsModuleProxy,
66
+ const bool isDevBundle,
67
+ jsi::Runtime &rt,
68
+ const jsi::Value &name,
69
+ const jsi::Value &initializer) {
70
+ auto workletRuntime = std::make_shared<WorkletRuntime>(
71
+ rt,
72
+ std::move(jsiWorkletsModuleProxy),
73
+ jsQueue,
74
+ jsScheduler,
75
+ name.asString(rt).utf8(rt),
76
+ true /* supportsLocking */,
77
+ isDevBundle);
78
+ auto initializerShareable = extractShareableOrThrow<ShareableWorklet>(
79
+ rt, initializer, "[Worklets] Initializer must be a worklet.");
80
+ workletRuntime->runGuarded(initializerShareable);
81
+ return jsi::Object::createFromHostObject(rt, workletRuntime);
82
+ }
83
+
84
+ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
85
+ const bool isDevBundle,
86
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
87
+ const std::shared_ptr<JSScheduler> &jsScheduler,
88
+ const std::shared_ptr<UIScheduler> &uiScheduler,
89
+ std::shared_ptr<WorkletRuntime> uiWorkletRuntime)
90
+ : jsi::HostObject(),
91
+ isDevBundle_(isDevBundle),
92
+ jsQueue_(jsQueue),
93
+ jsScheduler_(jsScheduler),
94
+ uiScheduler_(uiScheduler),
95
+ uiWorkletRuntime_(uiWorkletRuntime) {}
96
+
97
+ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
98
+ const JSIWorkletsModuleProxy &other)
99
+ : jsi::HostObject(),
100
+ isDevBundle_(other.isDevBundle_),
101
+ jsQueue_(other.jsQueue_),
102
+ jsScheduler_(other.jsScheduler_),
103
+ uiScheduler_(other.uiScheduler_),
104
+ uiWorkletRuntime_(other.uiWorkletRuntime_) {}
105
+
106
+ JSIWorkletsModuleProxy::~JSIWorkletsModuleProxy() = default;
107
+
108
+ std::vector<jsi::PropNameID> JSIWorkletsModuleProxy::getPropertyNames(
109
+ jsi::Runtime &rt) {
110
+ std::vector<jsi::PropNameID> propertyNames;
111
+
112
+ propertyNames.emplace_back(
113
+ jsi::PropNameID::forAscii(rt, "makeShareableClone"));
114
+ propertyNames.emplace_back(
115
+ jsi::PropNameID::forAscii(rt, "makeShareableBigInt"));
116
+ propertyNames.emplace_back(
117
+ jsi::PropNameID::forAscii(rt, "makeShareableBoolean"));
118
+ propertyNames.emplace_back(
119
+ jsi::PropNameID::forAscii(rt, "makeShareableNull"));
120
+ propertyNames.emplace_back(
121
+ jsi::PropNameID::forAscii(rt, "makeShareableNumber"));
122
+ propertyNames.emplace_back(
123
+ jsi::PropNameID::forAscii(rt, "makeShareableString"));
124
+ propertyNames.emplace_back(
125
+ jsi::PropNameID::forAscii(rt, "makeShareableUndefined"));
126
+
127
+ propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "scheduleOnUI"));
128
+ propertyNames.emplace_back(
129
+ jsi::PropNameID::forAscii(rt, "executeOnUIRuntimeSync"));
130
+ propertyNames.emplace_back(
131
+ jsi::PropNameID::forAscii(rt, "createWorkletRuntime"));
132
+ propertyNames.emplace_back(
133
+ jsi::PropNameID::forAscii(rt, "scheduleOnRuntime"));
134
+
135
+ return propertyNames;
136
+ }
137
+
138
+ jsi::Value JSIWorkletsModuleProxy::get(
139
+ jsi::Runtime &rt,
140
+ const jsi::PropNameID &propName) {
141
+ const auto name = propName.utf8(rt);
142
+ if (name == "makeShareableClone") {
143
+ return jsi::Function::createFromHostFunction(
144
+ rt,
145
+ propName,
146
+ 3,
147
+ [](jsi::Runtime &rt,
148
+ const jsi::Value &thisValue,
149
+ const jsi::Value *args,
150
+ size_t count) {
151
+ return makeShareableClone(rt, args[0], args[1], args[2]);
152
+ });
153
+ }
154
+ if (name == "makeShareableBigInt") {
155
+ return jsi::Function::createFromHostFunction(
156
+ rt,
157
+ propName,
158
+ 1,
159
+ [](jsi::Runtime &rt,
160
+ const jsi::Value &thisValue,
161
+ const jsi::Value *args,
162
+ size_t count) {
163
+ return makeShareableBigInt(rt, args[0].asBigInt(rt));
164
+ });
165
+ }
166
+ if (name == "makeShareableBoolean") {
167
+ return jsi::Function::createFromHostFunction(
168
+ rt,
169
+ propName,
170
+ 1,
171
+ [](jsi::Runtime &rt,
172
+ const jsi::Value &thisValue,
173
+ const jsi::Value *args,
174
+ size_t count) {
175
+ return makeShareableBoolean(rt, args[0].asBool());
176
+ });
177
+ }
178
+ if (name == "makeShareableNumber") {
179
+ return jsi::Function::createFromHostFunction(
180
+ rt,
181
+ propName,
182
+ 1,
183
+ [](jsi::Runtime &rt,
184
+ const jsi::Value &thisValue,
185
+ const jsi::Value *args,
186
+ size_t count) {
187
+ return makeShareableNumber(rt, args[0].asNumber());
188
+ });
189
+ }
190
+ if (name == "makeShareableNull") {
191
+ return jsi::Function::createFromHostFunction(
192
+ rt,
193
+ propName,
194
+ 0,
195
+ [](jsi::Runtime &rt,
196
+ const jsi::Value &thisValue,
197
+ const jsi::Value *args,
198
+ size_t count) { return makeShareableNull(rt); });
199
+ }
200
+ if (name == "makeShareableString") {
201
+ return jsi::Function::createFromHostFunction(
202
+ rt,
203
+ propName,
204
+ 1,
205
+ [](jsi::Runtime &rt,
206
+ const jsi::Value &thisValue,
207
+ const jsi::Value *args,
208
+ size_t count) {
209
+ return makeShareableString(rt, args[0].asString(rt));
210
+ });
211
+ }
212
+ if (name == "makeShareableUndefined") {
213
+ return jsi::Function::createFromHostFunction(
214
+ rt,
215
+ propName,
216
+ 0,
217
+ [](jsi::Runtime &rt,
218
+ const jsi::Value &thisValue,
219
+ const jsi::Value *args,
220
+ size_t count) { return makeShareableUndefined(rt); });
221
+ }
222
+ if (name == "scheduleOnUI") {
223
+ return jsi::Function::createFromHostFunction(
224
+ rt,
225
+ propName,
226
+ 1,
227
+ [uiScheduler = uiScheduler_, uiWorkletRuntime = uiWorkletRuntime_](
228
+ jsi::Runtime &rt,
229
+ const jsi::Value &thisValue,
230
+ const jsi::Value *args,
231
+ size_t count) {
232
+ scheduleOnUI(uiScheduler, uiWorkletRuntime, rt, args[0]);
233
+ return jsi::Value::undefined();
234
+ });
235
+ } else if (name == "executeOnUIRuntimeSync") {
236
+ return jsi::Function::createFromHostFunction(
237
+ rt,
238
+ propName,
239
+ 1,
240
+ [uiWorkletRuntime = uiWorkletRuntime_](
241
+ jsi::Runtime &rt,
242
+ const jsi::Value &thisValue,
243
+ const jsi::Value *args,
244
+ size_t count) {
245
+ return executeOnUIRuntimeSync(uiWorkletRuntime, rt, args[0]);
246
+ });
247
+ } else if (name == "createWorkletRuntime") {
248
+ auto clone = std::make_shared<JSIWorkletsModuleProxy>(*this);
249
+ return jsi::Function::createFromHostFunction(
250
+ rt,
251
+ propName,
252
+ 2,
253
+ [jsQueue = jsQueue_,
254
+ jsScheduler = jsScheduler_,
255
+ isDevBundle = isDevBundle_,
256
+ clone](
257
+ jsi::Runtime &rt,
258
+ const jsi::Value &thisValue,
259
+ const jsi::Value *args,
260
+ size_t count) {
261
+ return createWorkletRuntime(
262
+ jsQueue,
263
+ jsScheduler,
264
+ std::move(clone),
265
+ isDevBundle,
266
+ rt,
267
+ args[0],
268
+ args[1]);
269
+ return jsi::Value::undefined();
270
+ });
271
+ } else if (name == "scheduleOnRuntime") {
272
+ return jsi::Function::createFromHostFunction(
273
+ rt,
274
+ propName,
275
+ 2,
276
+ [](jsi::Runtime &rt,
277
+ const jsi ::Value &thisValue,
278
+ const jsi::Value *args,
279
+ size_t count) {
280
+ worklets::scheduleOnRuntime(rt, args[0], args[1]);
281
+ return jsi::Value::undefined();
282
+ });
283
+ }
284
+
285
+ return jsi::Value::undefined();
286
+ }
287
+
288
+ } // namespace worklets
@@ -0,0 +1,51 @@
1
+
2
+ #pragma once
3
+
4
+ #include <react/renderer/uimanager/UIManagerBinding.h>
5
+ #include <react/renderer/uimanager/primitives.h>
6
+
7
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
8
+ #include <worklets/SharedItems/Shareables.h>
9
+ #include <worklets/Tools/Defs.h>
10
+ #include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
11
+
12
+ #ifdef __ANDROID__
13
+ #include <fbjni/fbjni.h>
14
+ #endif // __ANDROID__
15
+
16
+ #include <jsi/jsi.h>
17
+
18
+ #include <memory>
19
+ #include <vector>
20
+
21
+ using namespace facebook;
22
+
23
+ namespace worklets {
24
+
25
+ class JSIWorkletsModuleProxy : public jsi::HostObject {
26
+ public:
27
+ explicit JSIWorkletsModuleProxy(
28
+ const bool isDevBundle,
29
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
30
+ const std::shared_ptr<JSScheduler> &jsScheduler,
31
+ const std::shared_ptr<UIScheduler> &uiScheduler,
32
+ std::shared_ptr<WorkletRuntime> uiWorkletRuntime);
33
+
34
+ JSIWorkletsModuleProxy(const JSIWorkletsModuleProxy &other);
35
+
36
+ ~JSIWorkletsModuleProxy() override;
37
+
38
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
39
+
40
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override;
41
+
42
+ private:
43
+ const bool isDevBundle_;
44
+ const std::shared_ptr<MessageQueueThread> jsQueue_;
45
+ const std::shared_ptr<JSScheduler> jsScheduler_;
46
+ const std::shared_ptr<UIScheduler> uiScheduler_;
47
+ // TODO: Make it non-nullptr on the UI runtime.
48
+ std::weak_ptr<WorkletRuntime> uiWorkletRuntime_;
49
+ };
50
+
51
+ } // namespace worklets
@@ -1,6 +1,7 @@
1
1
  #include <react/renderer/uimanager/UIManagerBinding.h>
2
2
  #include <react/renderer/uimanager/primitives.h>
3
3
 
4
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
4
5
  #include <worklets/NativeModules/WorkletsModuleProxy.h>
5
6
  #include <worklets/SharedItems/Shareables.h>
6
7
  #include <worklets/Tools/Defs.h>
@@ -10,10 +11,7 @@
10
11
  #include <fbjni/fbjni.h>
11
12
  #endif // __ANDROID__
12
13
 
13
- #include <jsi/jsi.h>
14
-
15
14
  #include <memory>
16
- #include <string>
17
15
  #include <utility>
18
16
 
19
17
  using namespace facebook;
@@ -29,13 +27,13 @@ WorkletsModuleProxy::WorkletsModuleProxy(
29
27
  const std::shared_ptr<UIScheduler> &uiScheduler,
30
28
  std::function<void(std::function<void(const double)>)>
31
29
  &&forwardedRequestAnimationFrame)
32
- : WorkletsModuleProxySpec(jsCallInvoker),
33
- isDevBundle_(isDevBundleFromRNRuntime(rnRuntime)),
30
+ : isDevBundle_(isDevBundleFromRNRuntime(rnRuntime)),
34
31
  jsQueue_(jsQueue),
35
32
  jsScheduler_(std::make_shared<JSScheduler>(rnRuntime, jsCallInvoker)),
36
33
  uiScheduler_(uiScheduler),
37
34
  uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
38
35
  rnRuntime,
36
+ createJSIWorkletsModuleProxy(),
39
37
  jsQueue,
40
38
  jsScheduler_,
41
39
  "Reanimated UI runtime",
@@ -49,117 +47,18 @@ WorkletsModuleProxy::WorkletsModuleProxy(
49
47
  animationFrameBatchinator_->getJsiRequestAnimationFrame());
50
48
  }
51
49
 
50
+ std::shared_ptr<jsi::HostObject>
51
+ WorkletsModuleProxy::createJSIWorkletsModuleProxy() const {
52
+ return std::make_shared<JSIWorkletsModuleProxy>(
53
+ isDevBundle_, jsQueue_, jsScheduler_, uiScheduler_, uiWorkletRuntime_);
54
+ }
55
+
52
56
  WorkletsModuleProxy::~WorkletsModuleProxy() {
53
57
  animationFrameBatchinator_.reset();
54
58
  jsQueue_->quitSynchronous();
55
59
  uiWorkletRuntime_.reset();
56
60
  }
57
61
 
58
- jsi::Value WorkletsModuleProxy::makeShareableClone(
59
- jsi::Runtime &rt,
60
- const jsi::Value &value,
61
- const jsi::Value &shouldRetainRemote,
62
- const jsi::Value &nativeStateSource) {
63
- // TODO: It might be a good idea to rename one of these methods to avoid
64
- // confusion.
65
- return worklets::makeShareableClone(
66
- rt, value, shouldRetainRemote, nativeStateSource);
67
- }
68
-
69
- jsi::Value WorkletsModuleProxy::makeShareableString(
70
- jsi::Runtime &rt,
71
- const jsi::String &string) {
72
- return worklets::makeShareableString(rt, string);
73
- }
74
-
75
- jsi::Value WorkletsModuleProxy::makeShareableNumber(
76
- jsi::Runtime &rt,
77
- double number) {
78
- return worklets::makeShareableNumber(rt, number);
79
- }
80
-
81
- jsi::Value WorkletsModuleProxy::makeShareableBoolean(
82
- jsi::Runtime &rt,
83
- bool boolean) {
84
- return worklets::makeShareableBoolean(rt, boolean);
85
- }
86
-
87
- jsi::Value WorkletsModuleProxy::makeShareableBigInt(
88
- jsi::Runtime &rt,
89
- const jsi::BigInt &bigint) {
90
- return worklets::makeShareableBigInt(rt, bigint);
91
- }
92
-
93
- jsi::Value WorkletsModuleProxy::makeShareableUndefined(jsi::Runtime &rt) {
94
- return worklets::makeShareableUndefined(rt);
95
- }
96
-
97
- jsi::Value WorkletsModuleProxy::makeShareableNull(jsi::Runtime &rt) {
98
- return worklets::makeShareableNull(rt);
99
- }
100
-
101
- void WorkletsModuleProxy::scheduleOnUI(
102
- jsi::Runtime &rt,
103
- const jsi::Value &worklet) {
104
- auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
105
- rt, worklet, "[Worklets] Only worklets can be scheduled to run on UI.");
106
- uiScheduler_->scheduleOnUI([shareableWorklet, weakThis = weak_from_this()] {
107
- // This callback can outlive the WorkletsModuleProxy object during the
108
- // invalidation of React Native. This happens when WorkletsModuleProxy
109
- // destructor is called on the JS thread and the UI thread is executing
110
- // callbacks from the `scheduleOnUI` queue. Therefore, we need to
111
- // make sure it's still alive before we try to access it.
112
- auto strongThis = weakThis.lock();
113
- if (!strongThis) {
114
- return;
115
- }
116
-
117
- auto uiWorkletRuntime = strongThis->getUIWorkletRuntime();
118
-
119
- #if JS_RUNTIME_HERMES
120
- // JSI's scope defined here allows for JSI-objects to be cleared up
121
- // after each runtime loop. Within these loops we typically create some
122
- // temporary JSI objects and hence it allows for such objects to be
123
- // garbage collected much sooner. Apparently the scope API is only
124
- // supported on Hermes at the moment.
125
- const auto scope = jsi::Scope(uiWorkletRuntime->getJSIRuntime());
126
- #endif // JS_RUNTIME_HERMES
127
-
128
- uiWorkletRuntime->runGuarded(shareableWorklet);
129
- });
130
- }
131
-
132
- jsi::Value WorkletsModuleProxy::executeOnUIRuntimeSync(
133
- jsi::Runtime &rt,
134
- const jsi::Value &worklet) {
135
- return uiWorkletRuntime_->executeSync(rt, worklet);
136
- }
137
-
138
- jsi::Value WorkletsModuleProxy::createWorkletRuntime(
139
- jsi::Runtime &rt,
140
- const jsi::Value &name,
141
- const jsi::Value &initializer) {
142
- auto workletRuntime = std::make_shared<WorkletRuntime>(
143
- rt,
144
- jsQueue_,
145
- jsScheduler_,
146
- name.asString(rt).utf8(rt),
147
- true /* supportsLocking */,
148
- isDevBundle_);
149
- auto initializerShareable = extractShareableOrThrow<ShareableWorklet>(
150
- rt, initializer, "[Worklets] Initializer must be a worklet.");
151
- workletRuntime->runGuarded(initializerShareable);
152
- return jsi::Object::createFromHostObject(rt, workletRuntime);
153
- }
154
-
155
- jsi::Value WorkletsModuleProxy::scheduleOnRuntime(
156
- jsi::Runtime &rt,
157
- const jsi::Value &workletRuntimeValue,
158
- const jsi::Value &shareableWorkletValue) {
159
- worklets::scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
160
- return jsi::Value::undefined();
161
- }
162
-
163
62
  auto isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime) -> bool {
164
63
  const auto rtDev = rnRuntime.global().getProperty(rnRuntime, "__DEV__");
165
64
  return rtDev.isBool() && rtDev.asBool();
@@ -1,21 +1,19 @@
1
1
  #pragma once
2
2
 
3
3
  #include <cxxreact/MessageQueueThread.h>
4
+ #include <jsi/jsi.h>
4
5
  #include <worklets/AnimationFrameQueue/AnimationFrameBatchinator.h>
5
- #include <worklets/NativeModules/WorkletsModuleProxySpec.h>
6
6
  #include <worklets/Tools/JSScheduler.h>
7
7
  #include <worklets/Tools/SingleInstanceChecker.h>
8
8
  #include <worklets/Tools/UIScheduler.h>
9
9
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
10
10
 
11
11
  #include <memory>
12
- #include <string>
13
12
 
14
13
  namespace worklets {
15
14
 
16
15
  class WorkletsModuleProxy
17
- : public WorkletsModuleProxySpec,
18
- public std::enable_shared_from_this<WorkletsModuleProxy> {
16
+ : public std::enable_shared_from_this<WorkletsModuleProxy> {
19
17
  public:
20
18
  explicit WorkletsModuleProxy(
21
19
  jsi::Runtime &rnRuntime,
@@ -25,42 +23,7 @@ class WorkletsModuleProxy
25
23
  std::function<void(std::function<void(const double)>)>
26
24
  &&forwardedRequestAnimationFrame);
27
25
 
28
- ~WorkletsModuleProxy() override;
29
-
30
- jsi::Value makeShareableClone(
31
- jsi::Runtime &rt,
32
- const jsi::Value &value,
33
- const jsi::Value &shouldRetainRemote,
34
- const jsi::Value &nativeStateSource) override;
35
-
36
- jsi::Value makeShareableString(jsi::Runtime &rt, const jsi::String &string)
37
- override;
38
-
39
- jsi::Value makeShareableNumber(jsi::Runtime &rt, double number) override;
40
-
41
- jsi::Value makeShareableBoolean(jsi::Runtime &rt, bool boolean) override;
42
-
43
- jsi::Value makeShareableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint)
44
- override;
45
-
46
- jsi::Value makeShareableUndefined(jsi::Runtime &rt) override;
47
-
48
- jsi::Value makeShareableNull(jsi::Runtime &rt) override;
49
-
50
- void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) override;
51
-
52
- jsi::Value executeOnUIRuntimeSync(jsi::Runtime &rt, const jsi::Value &worklet)
53
- override;
54
-
55
- jsi::Value createWorkletRuntime(
56
- jsi::Runtime &rt,
57
- const jsi::Value &name,
58
- const jsi::Value &initializer) override;
59
-
60
- jsi::Value scheduleOnRuntime(
61
- jsi::Runtime &rt,
62
- const jsi::Value &workletRuntimeValue,
63
- const jsi::Value &shareableWorkletValue) override;
26
+ ~WorkletsModuleProxy();
64
27
 
65
28
  [[nodiscard]] inline std::shared_ptr<MessageQueueThread> getJSQueue() const {
66
29
  return jsQueue_;
@@ -79,6 +42,9 @@ class WorkletsModuleProxy
79
42
  return uiWorkletRuntime_;
80
43
  }
81
44
 
45
+ [[nodiscard]] std::shared_ptr<jsi::HostObject> createJSIWorkletsModuleProxy()
46
+ const;
47
+
82
48
  [[nodiscard]] inline bool isDevBundle() const {
83
49
  return isDevBundle_;
84
50
  }
@@ -1,4 +1,7 @@
1
1
  #include <worklets/Tools/WorkletsJSIUtils.h>
2
+
3
+ #include <memory>
4
+ #include <sstream>
2
5
  #include <vector>
3
6
 
4
7
  using namespace facebook;
@@ -23,4 +26,15 @@ jsi::Array convertStringToArray(
23
26
  return matrix;
24
27
  }
25
28
 
29
+ jsi::Object optimizedFromHostObject(
30
+ jsi::Runtime &rt,
31
+ std::shared_ptr<jsi::HostObject> &&hostObject) {
32
+ auto optimizedObject = jsi::Object(rt);
33
+ for (const auto &propertyName : hostObject->getPropertyNames(rt)) {
34
+ optimizedObject.setProperty(
35
+ rt, propertyName, hostObject->get(rt, propertyName));
36
+ }
37
+ return optimizedObject;
38
+ }
39
+
26
40
  } // namespace worklets::jsi_utils
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
- #include <sstream>
4
+ #include <memory>
5
5
  #include <string>
6
6
  #include <tuple>
7
7
  #include <utility>
@@ -196,4 +196,8 @@ jsi::Array convertStringToArray(
196
196
  const std::string &value,
197
197
  const unsigned int expectedSize);
198
198
 
199
+ jsi::Object optimizedFromHostObject(
200
+ jsi::Runtime &rt,
201
+ std::shared_ptr<jsi::HostObject> &&hostObject);
202
+
199
203
  } // namespace worklets::jsi_utils
@@ -1,11 +1,13 @@
1
1
  #include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
2
2
  #include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
3
3
 
4
+ #include <utility>
5
+
4
6
  namespace worklets {
5
7
 
6
8
  void RNRuntimeWorkletDecorator::decorate(
7
9
  jsi::Runtime &rnRuntime,
8
- const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy) {
10
+ jsi::Object &&jsiWorkletsModuleProxy) {
9
11
  rnRuntime.global().setProperty(rnRuntime, "_WORKLET", false);
10
12
 
11
13
  // TODO: Remove _IS_FABRIC sometime in the future
@@ -13,9 +15,7 @@ void RNRuntimeWorkletDecorator::decorate(
13
15
  rnRuntime.global().setProperty(rnRuntime, "_IS_FABRIC", true);
14
16
 
15
17
  rnRuntime.global().setProperty(
16
- rnRuntime,
17
- "__workletsModuleProxy",
18
- jsi::Object::createFromHostObject(rnRuntime, workletsModuleProxy));
18
+ rnRuntime, "__workletsModuleProxy", std::move(jsiWorkletsModuleProxy));
19
19
 
20
20
  WorkletRuntimeCollector::install(rnRuntime);
21
21
  }
@@ -13,7 +13,7 @@ class RNRuntimeWorkletDecorator {
13
13
  public:
14
14
  static void decorate(
15
15
  jsi::Runtime &rnRuntime,
16
- const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy);
16
+ jsi::Object &&jsiWorkletsModuleProxy);
17
17
  };
18
18
 
19
19
  } // namespace worklets
@@ -1,6 +1,7 @@
1
1
  #include <worklets/Resources/ValueUnpacker.h>
2
2
  #include <worklets/Tools/Defs.h>
3
3
  #include <worklets/Tools/JSISerializer.h>
4
+ #include <worklets/Tools/WorkletsJSIUtils.h>
4
5
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
5
6
  #include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
6
7
  #include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
@@ -82,6 +83,7 @@ static std::shared_ptr<jsi::Runtime> makeRuntime(
82
83
 
83
84
  WorkletRuntime::WorkletRuntime(
84
85
  jsi::Runtime &rnRuntime,
86
+ std::shared_ptr<jsi::HostObject> &&jsiWorkletsModuleProxy,
85
87
  const std::shared_ptr<MessageQueueThread> &jsQueue,
86
88
  const std::shared_ptr<JSScheduler> &jsScheduler,
87
89
  const std::string &name,
@@ -100,7 +102,16 @@ WorkletRuntime::WorkletRuntime(
100
102
  name_(name) {
101
103
  jsi::Runtime &rt = *runtime_;
102
104
  WorkletRuntimeCollector::install(rt);
103
- WorkletRuntimeDecorator::decorate(rt, name, jsScheduler, isDevBundle);
105
+
106
+ auto optimizedJsiWorkletsModuleProxy =
107
+ jsi_utils::optimizedFromHostObject(rt, std::move(jsiWorkletsModuleProxy));
108
+
109
+ WorkletRuntimeDecorator::decorate(
110
+ rt,
111
+ name,
112
+ jsScheduler,
113
+ isDevBundle,
114
+ std::move(optimizedJsiWorkletsModuleProxy));
104
115
 
105
116
  auto valueUnpackerBuffer =
106
117
  std::make_shared<const jsi::StringBuffer>(ValueUnpackerCode);
@@ -22,6 +22,7 @@ class WorkletRuntime : public jsi::HostObject,
22
22
  public:
23
23
  explicit WorkletRuntime(
24
24
  jsi::Runtime &rnRuntime,
25
+ std::shared_ptr<jsi::HostObject> &&jsiWorkletsModuleProxy,
25
26
  const std::shared_ptr<MessageQueueThread> &jsQueue,
26
27
  const std::shared_ptr<JSScheduler> &jsScheduler,
27
28
  const std::string &name,
@@ -5,6 +5,7 @@
5
5
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
6
6
  #include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
7
7
 
8
+ #include <utility>
8
9
  #include <vector>
9
10
 
10
11
  namespace worklets {
@@ -40,7 +41,8 @@ void WorkletRuntimeDecorator::decorate(
40
41
  jsi::Runtime &rt,
41
42
  const std::string &name,
42
43
  const std::shared_ptr<JSScheduler> &jsScheduler,
43
- const bool isDevBundle) {
44
+ const bool isDevBundle,
45
+ jsi::Object &&jsiWorkletsModuleProxy) {
44
46
  // resolves "ReferenceError: Property 'global' doesn't exist at ..."
45
47
  rt.global().setProperty(rt, "global", rt.global());
46
48
 
@@ -54,6 +56,9 @@ void WorkletRuntimeDecorator::decorate(
54
56
 
55
57
  rt.global().setProperty(rt, "__DEV__", isDevBundle);
56
58
 
59
+ rt.global().setProperty(
60
+ rt, "__workletsModuleProxy", std::move(jsiWorkletsModuleProxy));
61
+
57
62
  #ifndef NDEBUG
58
63
  auto evalWithSourceUrl = [](jsi::Runtime &rt,
59
64
  const jsi::Value &thisValue,
@@ -17,7 +17,8 @@ class WorkletRuntimeDecorator {
17
17
  jsi::Runtime &rt,
18
18
  const std::string &name,
19
19
  const std::shared_ptr<JSScheduler> &jsScheduler,
20
- const bool isDevBundle);
20
+ const bool isDevBundle,
21
+ jsi::Object &&jsiWorkletsModuleProxy);
21
22
  };
22
23
 
23
24
  } // namespace worklets
@@ -1,5 +1,6 @@
1
1
  #include <react/jni/JMessageQueueThread.h>
2
2
 
3
+ #include <worklets/Tools/WorkletsJSIUtils.h>
3
4
  #include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
4
5
  #include <worklets/android/AnimationFrameCallback.h>
5
6
  #include <worklets/android/WorkletsModule.h>
@@ -25,7 +26,12 @@ WorkletsModule::WorkletsModule(
25
26
  jsCallInvoker,
26
27
  uiScheduler,
27
28
  getForwardedRequestAnimationFrame())) {
28
- RNRuntimeWorkletDecorator::decorate(*rnRuntime_, workletsModuleProxy_);
29
+ auto jsiWorkletsModuleProxy =
30
+ workletsModuleProxy_->createJSIWorkletsModuleProxy();
31
+ auto optimizedJsiWorkletsModuleProxy = jsi_utils::optimizedFromHostObject(
32
+ *rnRuntime_, std::move(jsiWorkletsModuleProxy));
33
+ RNRuntimeWorkletDecorator::decorate(
34
+ *rnRuntime_, std::move(optimizedJsiWorkletsModuleProxy));
29
35
  }
30
36
 
31
37
  jni::local_ref<WorkletsModule::jhybriddata> WorkletsModule::initHybrid(
@@ -1,4 +1,5 @@
1
1
  #import <worklets/Tools/SingleInstanceChecker.h>
2
+ #import <worklets/Tools/WorkletsJSIUtils.h>
2
3
  #import <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
3
4
  #import <worklets/apple/AnimationFrameQueue.h>
4
5
  #import <worklets/apple/AssertJavaScriptQueue.h>
@@ -64,7 +65,10 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule)
64
65
  });
65
66
  workletsModuleProxy_ = std::make_shared<WorkletsModuleProxy>(
66
67
  rnRuntime, jsQueue, jsCallInvoker, uiScheduler, std::move(forwardedRequestAnimationFrame));
67
- RNRuntimeWorkletDecorator::decorate(rnRuntime, workletsModuleProxy_);
68
+ auto jsiWorkletsModuleProxy = workletsModuleProxy_->createJSIWorkletsModuleProxy();
69
+ auto optimizedJsiWorkletsModuleProxy =
70
+ worklets::jsi_utils::optimizedFromHostObject(rnRuntime, std::move(jsiWorkletsModuleProxy));
71
+ RNRuntimeWorkletDecorator::decorate(rnRuntime, std::move(optimizedJsiWorkletsModuleProxy));
68
72
 
69
73
  return @YES;
70
74
  }
@@ -20,19 +20,7 @@ class NativeWorklets {
20
20
  throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
21
21
  See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#native-part-of-reanimated-doesnt-seem-to-be-initialized for more details.`);
22
22
  }
23
- this.#workletsModuleProxy = {
24
- scheduleOnUI: global.__workletsModuleProxy.scheduleOnUI,
25
- scheduleOnRuntime: global.__workletsModuleProxy.scheduleOnRuntime,
26
- executeOnUIRuntimeSync: global.__workletsModuleProxy.executeOnUIRuntimeSync,
27
- createWorkletRuntime: global.__workletsModuleProxy.createWorkletRuntime,
28
- makeShareableClone: global.__workletsModuleProxy.makeShareableClone,
29
- makeShareableString: global.__workletsModuleProxy.makeShareableString,
30
- makeShareableNumber: global.__workletsModuleProxy.makeShareableNumber,
31
- makeShareableBoolean: global.__workletsModuleProxy.makeShareableBoolean,
32
- makeShareableBigInt: global.__workletsModuleProxy.makeShareableBigInt,
33
- makeShareableUndefined: global.__workletsModuleProxy.makeShareableUndefined,
34
- makeShareableNull: global.__workletsModuleProxy.makeShareableNull
35
- };
23
+ this.#workletsModuleProxy = global.__workletsModuleProxy;
36
24
  this.#shareableNull = this.#workletsModuleProxy.makeShareableNull();
37
25
  this.#shareableUndefined = this.#workletsModuleProxy.makeShareableUndefined();
38
26
  this.#shareableTrue = this.#workletsModuleProxy.makeShareableBoolean(true);
@@ -1 +1 @@
1
- {"version":3,"names":["WorkletsTurboModule","WorkletsError","createNativeWorkletsModule","NativeWorklets","workletsModuleProxy","shareableUndefined","shareableNull","shareableTrue","shareableFalse","constructor","global","__workletsModuleProxy","undefined","installTurboModule","scheduleOnUI","scheduleOnRuntime","executeOnUIRuntimeSync","createWorkletRuntime","makeShareableClone","makeShareableString","makeShareableNumber","makeShareableBoolean","makeShareableBigInt","makeShareableUndefined","makeShareableNull","value","shouldPersistRemote","nativeStateSource","str","num","bool","bigInt","shareable","name","initializer","workletRuntime","shareableWorklet"],"sourceRoot":"../../../src","sources":["WorkletsModule/NativeWorklets.ts"],"mappings":"AAAA;AACA,YAAY;;AAEZ,SAASA,mBAAmB,QAAQ,mBAAU;AAC9C,SAASC,aAAa,QAAQ,qBAAkB;AAMhD,OAAO,SAASC,0BAA0BA,CAAA,EAAoB;EAC5D,OAAO,IAAIC,cAAc,CAAC,CAAC;AAC7B;AAEA,MAAMA,cAAc,CAAC;EACnB,CAACC,mBAAmB;EACpB,CAACC,kBAAkB;EACnB,CAACC,aAAa;EACd,CAACC,aAAa;EACd,CAACC,cAAc;EAEfC,WAAWA,CAAA,EAAG;IACZ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oB,cAA8B,EAC9BC,gBAAiC,EACjC;IACA,OAAO,IAAI,CAAC,CAAChC,mBAAmB,CAACW,iBAAiB,CAChDoB,cAAc,EACdC,gBACF,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"names":["WorkletsTurboModule","WorkletsError","createNativeWorkletsModule","NativeWorklets","workletsModuleProxy","shareableUndefined","shareableNull","shareableTrue","shareableFalse","constructor","global","__workletsModuleProxy","undefined","installTurboModule","makeShareableNull","makeShareableUndefined","makeShareableBoolean","makeShareableClone","value","shouldPersistRemote","nativeStateSource","makeShareableString","str","makeShareableNumber","num","bool","makeShareableBigInt","bigInt","scheduleOnUI","shareable","executeOnUIRuntimeSync","createWorkletRuntime","name","initializer","scheduleOnRuntime","workletRuntime","shareableWorklet"],"sourceRoot":"../../../src","sources":["WorkletsModule/NativeWorklets.ts"],"mappings":"AAAA;AACA,YAAY;;AAEZ,SAASA,mBAAmB,QAAQ,mBAAU;AAC9C,SAASC,aAAa,QAAQ,qBAAkB;AAMhD,OAAO,SAASC,0BAA0BA,CAAA,EAAoB;EAC5D,OAAO,IAAIC,cAAc,CAAC,CAAC;AAC7B;AAEA,MAAMA,cAAc,CAAC;EACnB,CAACC,mBAAmB;EACpB,CAACC,kBAAkB;EACnB,CAACC,aAAa;EACd,CAACC,aAAa;EACd,CAACC,cAAc;EAEfC,WAAWA,CAAA,EAAG;IACZ,IAAIC,MAAM,CAACC,qBAAqB,KAAKC,SAAS,EAAE;MAC9CZ,mBAAmB,EAAEa,kBAAkB,CAAC,CAAC;IAC3C;IACA,IAAIH,MAAM,CAACC,qBAAqB,KAAKC,SAAS,EAAE;MAC9C,MAAM,IAAIX,aAAa,CACrB;AACR,6JACM,CAAC;IACH;IACA,IAAI,CAAC,CAACG,mBAAmB,GAAGM,MAAM,CAACC,qBAAqB;IACxD,IAAI,CAAC,CAACL,aAAa,GAAG,IAAI,CAAC,CAACF,mBAAmB,CAACU,iBAAiB,CAAC,CAAC;IACnE,IAAI,CAAC,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CAAC,CAACzB,mBAAmB,CAAC0B,sBAAsB,CAACD,SAAS,CAAC;EACpE;EAEAE,oBAAoBA,CAACC,IAAY,EAAEC,WAAqC,EAAE;IACxE,OAAO,IAAI,CAAC,CAAC7B,mBAAmB,CAAC2B,oBAAoB,CAACC,IAAI,EAAEC,WAAW,CAAC;EAC1E;EAEAC,iBAAiBA,CACfC,cAA8B,EAC9BC,gBAAiC,EACjC;IACA,OAAO,IAAI,CAAC,CAAChC,mBAAmB,CAAC8B,iBAAiB,CAChDC,cAAc,EACdC,gBACF,CAAC;EACH;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-worklets",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-nightly-20250521-922379cf5",
4
4
  "description": "The React Native multithreading library",
5
5
  "keywords": [
6
6
  "react-native",
@@ -29,21 +29,7 @@ class NativeWorklets {
29
29
  See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#native-part-of-reanimated-doesnt-seem-to-be-initialized for more details.`
30
30
  );
31
31
  }
32
- this.#workletsModuleProxy = {
33
- scheduleOnUI: global.__workletsModuleProxy.scheduleOnUI,
34
- scheduleOnRuntime: global.__workletsModuleProxy.scheduleOnRuntime,
35
- executeOnUIRuntimeSync:
36
- global.__workletsModuleProxy.executeOnUIRuntimeSync,
37
- createWorkletRuntime: global.__workletsModuleProxy.createWorkletRuntime,
38
- makeShareableClone: global.__workletsModuleProxy.makeShareableClone,
39
- makeShareableString: global.__workletsModuleProxy.makeShareableString,
40
- makeShareableNumber: global.__workletsModuleProxy.makeShareableNumber,
41
- makeShareableBoolean: global.__workletsModuleProxy.makeShareableBoolean,
42
- makeShareableBigInt: global.__workletsModuleProxy.makeShareableBigInt,
43
- makeShareableUndefined:
44
- global.__workletsModuleProxy.makeShareableUndefined,
45
- makeShareableNull: global.__workletsModuleProxy.makeShareableNull,
46
- };
32
+ this.#workletsModuleProxy = global.__workletsModuleProxy;
47
33
  this.#shareableNull = this.#workletsModuleProxy.makeShareableNull();
48
34
  this.#shareableUndefined =
49
35
  this.#workletsModuleProxy.makeShareableUndefined();
@@ -1,139 +0,0 @@
1
- #include <jsi/jsi.h>
2
- #include <worklets/NativeModules/WorkletsModuleProxySpec.h>
3
-
4
- #include <utility>
5
-
6
- #define WORKLETS_SPEC_PREFIX(FN_NAME) \
7
- __hostFunction_WorkletsModuleProxySpec_##FN_NAME
8
-
9
- namespace worklets {
10
-
11
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableClone)(
12
- jsi::Runtime &rt,
13
- TurboModule &turboModule,
14
- const jsi::Value *args,
15
- size_t) {
16
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
17
- ->makeShareableClone(
18
- rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
19
- }
20
-
21
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableString)(
22
- jsi::Runtime &rt,
23
- TurboModule &turboModule,
24
- const jsi::Value *args,
25
- size_t) {
26
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
27
- ->makeShareableString(rt, std::move(args[0]).asString(rt));
28
- }
29
-
30
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableNumber)(
31
- jsi::Runtime &rt,
32
- TurboModule &turboModule,
33
- const jsi::Value *args,
34
- size_t) {
35
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
36
- ->makeShareableNumber(rt, std::move(args[0]).asNumber());
37
- }
38
-
39
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableBoolean)(
40
- jsi::Runtime &rt,
41
- TurboModule &turboModule,
42
- const jsi::Value *args,
43
- size_t) {
44
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
45
- ->makeShareableBoolean(rt, std::move(args[0]).asBool());
46
- }
47
-
48
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableBigInt)(
49
- jsi::Runtime &rt,
50
- TurboModule &turboModule,
51
- const jsi::Value *args,
52
- size_t) {
53
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
54
- ->makeShareableBigInt(rt, std::move(args[0]).asBigInt(rt));
55
- }
56
-
57
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableUndefined)(
58
- jsi::Runtime &rt,
59
- TurboModule &turboModule,
60
- const jsi::Value *args,
61
- size_t) {
62
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
63
- ->makeShareableUndefined(rt);
64
- }
65
-
66
- static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableNull)(
67
- jsi::Runtime &rt,
68
- TurboModule &turboModule,
69
- const jsi::Value *args,
70
- size_t) {
71
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
72
- ->makeShareableNull(rt);
73
- }
74
-
75
- static jsi::Value WORKLETS_SPEC_PREFIX(scheduleOnUI)(
76
- jsi::Runtime &rt,
77
- TurboModule &turboModule,
78
- const jsi::Value *args,
79
- size_t) {
80
- static_cast<WorkletsModuleProxySpec *>(&turboModule)
81
- ->scheduleOnUI(rt, std::move(args[0]));
82
- return jsi::Value::undefined();
83
- }
84
-
85
- static jsi::Value WORKLETS_SPEC_PREFIX(executeOnUIRuntimeSync)(
86
- jsi::Runtime &rt,
87
- TurboModule &turboModule,
88
- const jsi::Value *args,
89
- size_t) {
90
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
91
- ->executeOnUIRuntimeSync(rt, std::move(args[0]));
92
- }
93
-
94
- static jsi::Value WORKLETS_SPEC_PREFIX(createWorkletRuntime)(
95
- jsi::Runtime &rt,
96
- TurboModule &turboModule,
97
- const jsi::Value *args,
98
- size_t) {
99
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
100
- ->createWorkletRuntime(rt, std::move(args[0]), std::move(args[1]));
101
- }
102
-
103
- static jsi::Value WORKLETS_SPEC_PREFIX(scheduleOnRuntime)(
104
- jsi::Runtime &rt,
105
- TurboModule &turboModule,
106
- const jsi::Value *args,
107
- size_t) {
108
- return static_cast<WorkletsModuleProxySpec *>(&turboModule)
109
- ->scheduleOnRuntime(rt, std::move(args[0]), std::move(args[1]));
110
- }
111
-
112
- WorkletsModuleProxySpec::WorkletsModuleProxySpec(
113
- const std::shared_ptr<CallInvoker> jsInvoker)
114
- : TurboModule("NativeWorklets", jsInvoker) {
115
- methodMap_["makeShareableClone"] =
116
- MethodMetadata{2, WORKLETS_SPEC_PREFIX(makeShareableClone)};
117
- methodMap_["makeShareableString"] =
118
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(makeShareableString)};
119
- methodMap_["makeShareableNumber"] =
120
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(makeShareableNumber)};
121
- methodMap_["makeShareableBoolean"] =
122
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(makeShareableBoolean)};
123
- methodMap_["makeShareableBigInt"] =
124
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(makeShareableBigInt)};
125
- methodMap_["makeShareableUndefined"] =
126
- MethodMetadata{0, WORKLETS_SPEC_PREFIX(makeShareableUndefined)};
127
- methodMap_["makeShareableNull"] =
128
- MethodMetadata{0, WORKLETS_SPEC_PREFIX(makeShareableNull)};
129
- methodMap_["scheduleOnUI"] =
130
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(scheduleOnUI)};
131
- methodMap_["executeOnUIRuntimeSync"] =
132
- MethodMetadata{1, WORKLETS_SPEC_PREFIX(executeOnUIRuntimeSync)};
133
- methodMap_["createWorkletRuntime"] =
134
- MethodMetadata{2, WORKLETS_SPEC_PREFIX(createWorkletRuntime)};
135
- methodMap_["scheduleOnRuntime"] =
136
- MethodMetadata{2, WORKLETS_SPEC_PREFIX(scheduleOnRuntime)};
137
- }
138
-
139
- } // namespace worklets
@@ -1,61 +0,0 @@
1
- #pragma once
2
-
3
- #include <ReactCommon/CallInvoker.h>
4
- #include <ReactCommon/TurboModule.h>
5
- #include <memory>
6
- #include <string>
7
-
8
- using namespace facebook;
9
- using namespace react;
10
-
11
- namespace worklets {
12
-
13
- class JSI_EXPORT WorkletsModuleProxySpec : public TurboModule {
14
- protected:
15
- explicit WorkletsModuleProxySpec(
16
- const std::shared_ptr<CallInvoker> jsInvoker);
17
-
18
- public:
19
- // Shareables
20
- virtual jsi::Value makeShareableClone(
21
- jsi::Runtime &rt,
22
- const jsi::Value &value,
23
- const jsi::Value &shouldRetainRemote,
24
- const jsi::Value &nativeStateSource) = 0;
25
-
26
- virtual jsi::Value makeShareableString(
27
- jsi::Runtime &rt,
28
- const jsi::String &string) = 0;
29
-
30
- virtual jsi::Value makeShareableNumber(jsi::Runtime &rt, double number) = 0;
31
-
32
- virtual jsi::Value makeShareableBoolean(jsi::Runtime &rt, bool boolean) = 0;
33
-
34
- virtual jsi::Value makeShareableBigInt(
35
- jsi::Runtime &rt,
36
- const jsi::BigInt &bigint) = 0;
37
-
38
- virtual jsi::Value makeShareableUndefined(jsi::Runtime &rt) = 0;
39
-
40
- virtual jsi::Value makeShareableNull(jsi::Runtime &rt) = 0;
41
-
42
- // Scheduling
43
- virtual void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) = 0;
44
-
45
- virtual jsi::Value executeOnUIRuntimeSync(
46
- jsi::Runtime &rt,
47
- const jsi::Value &worklet) = 0;
48
-
49
- // Worklet runtime
50
- virtual jsi::Value createWorkletRuntime(
51
- jsi::Runtime &rt,
52
- const jsi::Value &name,
53
- const jsi::Value &initializer) = 0;
54
-
55
- virtual jsi::Value scheduleOnRuntime(
56
- jsi::Runtime &rt,
57
- const jsi::Value &workletRuntimeValue,
58
- const jsi::Value &shareableWorkletValue) = 0;
59
- };
60
-
61
- } // namespace worklets