Skip to content

Commit 6fad03e

Browse files
authored
feat(Worklets): Create a stub of Worklets Module (#6539)
This pull request is one of many which replace - #6378 since that PR is extensive and too difficult to review. ## Summary Adding a second Native Module for Worklets. It's initial responsibility for now is forwarding `valueUnpackerCode` to Reanimated Module. While it seems silly, it's a good start since it sets up the whole pipeline of: ```tree typescript ├── android │ └── cpp └── ios └── cpp ``` (I was too lazy to use mermaid, long live `mkdir -p`) Follow up PRs will move more and more responsibilities from Reanimated to Worklets. Requires: - #6556 - #6557 ## Test plan - [x] All GitHub Actions pass - [x] Compatibility Github Action passes - [x] debug Android works - [x] release Android works - [x] debug iOS works - [x] release iOS works
1 parent ef812a1 commit 6fad03e

File tree

47 files changed

+658
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+658
-115
lines changed

apps/fabric-example/ios/Podfile.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,28 @@ PODS:
18141814
- ReactCommon/turbomodule/core
18151815
- Yoga
18161816
- RNReanimated/worklets (3.17.0):
1817+
- DoubleConversion
1818+
- glog
1819+
- hermes-engine
1820+
- RCT-Folly (= 2024.01.01.00)
1821+
- RCTRequired
1822+
- RCTTypeSafety
1823+
- React-Core
1824+
- React-debug
1825+
- React-Fabric
1826+
- React-featureflags
1827+
- React-graphics
1828+
- React-ImageManager
1829+
- React-NativeModulesApple
1830+
- React-RCTFabric
1831+
- React-rendererdebug
1832+
- React-utils
1833+
- ReactCodegen
1834+
- ReactCommon/turbomodule/bridging
1835+
- ReactCommon/turbomodule/core
1836+
- RNReanimated/worklets/apple (= 3.17.0)
1837+
- Yoga
1838+
- RNReanimated/worklets/apple (3.17.0):
18171839
- DoubleConversion
18181840
- glog
18191841
- hermes-engine
@@ -2229,7 +2251,7 @@ SPEC CHECKSUMS:
22292251
RNCPicker: b978067931744f5a7316b48b8dcf145d4d722672
22302252
RNFlashList: 6f169ad83e52579b7754cbbcec1b004c27d82c93
22312253
RNGestureHandler: fc5ce5bf284640d3af6431c3a5c3bc121e98d045
2232-
RNReanimated: 2db902281618797873d75426f334ede4e503baf8
2254+
RNReanimated: c03f9fdff5fd382d1833c37fa0e6f64ffd9b8a92
22332255
RNScreens: 2fe13c8d610ef2d9d5ace2e7d85b716ec0f5217c
22342256
RNSVG: 536cd3c866c878faf72beaba166c8b02fe2b762b
22352257
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748

apps/macos-example/macos/Podfile.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,28 @@ PODS:
15471547
- ReactCommon/turbomodule/core
15481548
- Yoga
15491549
- RNReanimated/worklets (3.17.0):
1550+
- DoubleConversion
1551+
- glog
1552+
- RCT-Folly (= 2024.01.01.00)
1553+
- RCTRequired
1554+
- RCTTypeSafety
1555+
- React-Core
1556+
- React-debug
1557+
- React-Fabric
1558+
- React-featureflags
1559+
- React-graphics
1560+
- React-ImageManager
1561+
- React-jsi
1562+
- React-NativeModulesApple
1563+
- React-RCTFabric
1564+
- React-rendererdebug
1565+
- React-utils
1566+
- ReactCodegen
1567+
- ReactCommon/turbomodule/bridging
1568+
- ReactCommon/turbomodule/core
1569+
- RNReanimated/worklets/apple (= 3.17.0)
1570+
- Yoga
1571+
- RNReanimated/worklets/apple (3.17.0):
15501572
- DoubleConversion
15511573
- glog
15521574
- RCT-Folly (= 2024.01.01.00)
@@ -1843,7 +1865,7 @@ SPEC CHECKSUMS:
18431865
RNCAsyncStorage: ec53e44dc3e75b44aa2a9f37618a49c3bc080a7a
18441866
RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94
18451867
RNGestureHandler: 82f59e40580e0c2f8262552c149716511131b412
1846-
RNReanimated: 8b9e602d3bc250cfd046c584454aa2a2efa8bd7e
1868+
RNReanimated: ed490424d3b8b9f2acd104577c73b374fc79310b
18471869
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
18481870
SocketRocket: 9ee265c4b5ae2382d18e4ee1d2dd2d7af0ff1ab5
18491871
Yoga: a7f65c1fd1394973b9ea40c9c270530e9d7cd2e7

apps/paper-example/ios/Podfile.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,28 @@ PODS:
16681668
- ReactCommon/turbomodule/core
16691669
- Yoga
16701670
- RNReanimated/worklets (3.17.0):
1671+
- DoubleConversion
1672+
- glog
1673+
- hermes-engine
1674+
- RCT-Folly (= 2024.01.01.00)
1675+
- RCTRequired
1676+
- RCTTypeSafety
1677+
- React-Core
1678+
- React-debug
1679+
- React-Fabric
1680+
- React-featureflags
1681+
- React-graphics
1682+
- React-ImageManager
1683+
- React-NativeModulesApple
1684+
- React-RCTFabric
1685+
- React-rendererdebug
1686+
- React-utils
1687+
- ReactCodegen
1688+
- ReactCommon/turbomodule/bridging
1689+
- ReactCommon/turbomodule/core
1690+
- RNReanimated/worklets/apple (= 3.17.0)
1691+
- Yoga
1692+
- RNReanimated/worklets/apple (3.17.0):
16711693
- DoubleConversion
16721694
- glog
16731695
- hermes-engine
@@ -2019,7 +2041,7 @@ SPEC CHECKSUMS:
20192041
RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94
20202042
RNFlashList: 115dd44377580761bff386a0caebf165424cf16f
20212043
RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8
2022-
RNReanimated: 9ef3b1908a15b0b778edd6dacad9c71e7fe9e849
2044+
RNReanimated: 1d16252a3b482d884ba83b09800594fbfa773291
20232045
RNScreens: de948b09c9a30f3ea52f9840dd6f8ce92b4e33d3
20242046
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
20252047
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748

apps/tvos-example/ios/Podfile.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,28 @@ PODS:
15751575
- ReactCommon/turbomodule/core
15761576
- Yoga
15771577
- RNReanimated/worklets (3.17.0):
1578+
- DoubleConversion
1579+
- glog
1580+
- hermes-engine
1581+
- RCT-Folly (= 2024.01.01.00)
1582+
- RCTRequired
1583+
- RCTTypeSafety
1584+
- React-Core
1585+
- React-debug
1586+
- React-Fabric
1587+
- React-featureflags
1588+
- React-graphics
1589+
- React-ImageManager
1590+
- React-NativeModulesApple
1591+
- React-RCTFabric
1592+
- React-rendererdebug
1593+
- React-utils
1594+
- ReactCodegen
1595+
- ReactCommon/turbomodule/bridging
1596+
- ReactCommon/turbomodule/core
1597+
- RNReanimated/worklets/apple (= 3.17.0)
1598+
- Yoga
1599+
- RNReanimated/worklets/apple (3.17.0):
15781600
- DoubleConversion
15791601
- glog
15801602
- hermes-engine
@@ -1864,7 +1886,7 @@ SPEC CHECKSUMS:
18641886
React-utils: 3fce26d04c6776ddd47f255e7f3adc70d61b4491
18651887
ReactCodegen: 61cc9f25250fd53c91d30d82e84a1c6aafcf451a
18661888
ReactCommon: b927fd46115bd2acb146e24cf1a08f22abda8b3f
1867-
RNReanimated: b007fe1002350dd2ffb10fec214560a167794e12
1889+
RNReanimated: 3a5e1e235c940894097b0734aad9ebce45431ddd
18681890
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
18691891
Yoga: 651e5fd560c7e408ab9d9ca44b8de1b622d7f0cc
18701892

packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,30 @@ using namespace facebook;
5252
namespace reanimated {
5353

5454
NativeReanimatedModule::NativeReanimatedModule(
55+
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
5556
jsi::Runtime &rnRuntime,
5657
const std::shared_ptr<JSScheduler> &jsScheduler,
5758
const std::shared_ptr<MessageQueueThread> &jsQueue,
5859
const std::shared_ptr<UIScheduler> &uiScheduler,
5960
const PlatformDepMethodsHolder &platformDepMethodsHolder,
60-
const std::string &valueUnpackerCode,
6161
const bool isBridgeless,
6262
const bool isReducedMotion)
6363
: NativeReanimatedModuleSpec(
6464
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
6565
isBridgeless_(isBridgeless),
6666
isReducedMotion_(isReducedMotion),
6767
jsQueue_(jsQueue),
68+
nativeWorkletsModule_(nativeWorkletsModule),
6869
jsScheduler_(jsScheduler),
6970
uiScheduler_(uiScheduler),
71+
valueUnpackerCode_(nativeWorkletsModule->getValueUnpackerCode()),
7072
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
7173
rnRuntime,
7274
jsQueue,
7375
jsScheduler_,
7476
"Reanimated UI runtime",
7577
true /* supportsLocking */,
76-
valueUnpackerCode)),
77-
valueUnpackerCode_(valueUnpackerCode),
78+
valueUnpackerCode_)),
7879
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
7980
requestRender_(platformDepMethodsHolder.requestRender),
8081
onRenderCallback_([this](const double timestampMs) {

packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
1414
#endif // RCT_NEW_ARCH_ENABLED
1515

16+
#include <worklets/NativeModules/NativeWorkletsModule.h>
1617
#include <worklets/Registries/EventHandlerRegistry.h>
1718
#include <worklets/Tools/JSScheduler.h>
1819
#include <worklets/Tools/UIScheduler.h>
@@ -32,12 +33,12 @@ namespace reanimated {
3233
class NativeReanimatedModule : public NativeReanimatedModuleSpec {
3334
public:
3435
NativeReanimatedModule(
36+
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
3537
jsi::Runtime &rnRuntime,
3638
const std::shared_ptr<JSScheduler> &jsScheduler,
3739
const std::shared_ptr<MessageQueueThread> &jsQueue,
3840
const std::shared_ptr<UIScheduler> &uiScheduler,
3941
const PlatformDepMethodsHolder &platformDepMethodsHolder,
40-
const std::string &valueUnpackerCode,
4142
const bool isBridgeless,
4243
const bool isReducedMotion);
4344

@@ -168,18 +169,23 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
168169
return *layoutAnimationsManager_;
169170
}
170171

171-
inline jsi::Runtime &getUIRuntime() const {
172+
[[nodiscard]] inline jsi::Runtime &getUIRuntime() const {
172173
return uiWorkletRuntime_->getJSIRuntime();
173174
}
174175

175-
inline bool isBridgeless() const {
176+
[[nodiscard]] inline bool isBridgeless() const {
176177
return isBridgeless_;
177178
}
178179

179-
inline bool isReducedMotion() const {
180+
[[nodiscard]] inline bool isReducedMotion() const {
180181
return isReducedMotion_;
181182
}
182183

184+
[[nodiscard]] inline std::shared_ptr<NativeWorkletsModule>
185+
getNativeWorkletsModule() const {
186+
return nativeWorkletsModule_;
187+
}
188+
183189
private:
184190
void commonInit(const PlatformDepMethodsHolder &platformDepMethodsHolder);
185191

@@ -195,10 +201,11 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
195201
const bool isBridgeless_;
196202
const bool isReducedMotion_;
197203
const std::shared_ptr<MessageQueueThread> jsQueue_;
204+
const std::shared_ptr<NativeWorkletsModule> nativeWorkletsModule_;
198205
const std::shared_ptr<JSScheduler> jsScheduler_;
199206
const std::shared_ptr<UIScheduler> uiScheduler_;
207+
const std::string valueUnpackerCode_;
200208
std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
201-
std::string valueUnpackerCode_;
202209

203210
std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry_;
204211
const RequestRenderFunction requestRender_;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <string>
2+
3+
#ifdef RCT_NEW_ARCH_ENABLED
4+
#include <react/renderer/uimanager/UIManagerBinding.h>
5+
#include <react/renderer/uimanager/primitives.h>
6+
#endif // RCT_NEW_ARCH_ENABLED
7+
8+
#include <worklets/NativeModules/NativeWorkletsModule.h>
9+
10+
#ifdef __ANDROID__
11+
#include <fbjni/fbjni.h>
12+
#endif // __ANDROID__
13+
14+
#include <jsi/jsi.h>
15+
16+
using namespace facebook;
17+
18+
namespace worklets {
19+
20+
NativeWorkletsModule::NativeWorkletsModule(const std::string &valueUnpackerCode)
21+
: NativeWorkletsModuleSpec(nullptr),
22+
valueUnpackerCode_(valueUnpackerCode) {}
23+
24+
NativeWorkletsModule::~NativeWorkletsModule() {}
25+
} // namespace worklets
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <cxxreact/MessageQueueThread.h>
4+
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h>
5+
#include <string>
6+
7+
namespace worklets {
8+
9+
class NativeWorkletsModule : public NativeWorkletsModuleSpec {
10+
public:
11+
explicit NativeWorkletsModule(const std::string &valueUnpackerCode);
12+
13+
~NativeWorkletsModule();
14+
15+
[[nodiscard]] inline std::string getValueUnpackerCode() const {
16+
return valueUnpackerCode_;
17+
}
18+
19+
private:
20+
const std::string valueUnpackerCode_;
21+
};
22+
23+
} // namespace worklets
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h>
2+
3+
namespace worklets {
4+
5+
NativeWorkletsModuleSpec::NativeWorkletsModuleSpec(
6+
const std::shared_ptr<CallInvoker> jsInvoker)
7+
: TurboModule("NativeWorklets", jsInvoker) {}
8+
9+
} // namespace worklets
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <ReactCommon/CallInvoker.h>
4+
#include <ReactCommon/TurboModule.h>
5+
#include <memory>
6+
7+
using namespace facebook;
8+
using namespace react;
9+
10+
namespace worklets {
11+
12+
class JSI_EXPORT NativeWorkletsModuleSpec : public TurboModule {
13+
protected:
14+
explicit NativeWorkletsModuleSpec(
15+
const std::shared_ptr<CallInvoker> jsInvoker);
16+
};
17+
18+
} // namespace worklets

0 commit comments

Comments
 (0)