forked from software-mansion/react-native-reanimated
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Worklets): Create a stub of Worklets Module (software-mansion#6539)
This pull request is one of many which replace - software-mansion#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: - software-mansion#6556 - software-mansion#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
- Loading branch information
Showing
47 changed files
with
658 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <string> | ||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#include <react/renderer/uimanager/UIManagerBinding.h> | ||
#include <react/renderer/uimanager/primitives.h> | ||
#endif // RCT_NEW_ARCH_ENABLED | ||
|
||
#include <worklets/NativeModules/NativeWorkletsModule.h> | ||
|
||
#ifdef __ANDROID__ | ||
#include <fbjni/fbjni.h> | ||
#endif // __ANDROID__ | ||
|
||
#include <jsi/jsi.h> | ||
|
||
using namespace facebook; | ||
|
||
namespace worklets { | ||
|
||
NativeWorkletsModule::NativeWorkletsModule(const std::string &valueUnpackerCode) | ||
: NativeWorkletsModuleSpec(nullptr), | ||
valueUnpackerCode_(valueUnpackerCode) {} | ||
|
||
NativeWorkletsModule::~NativeWorkletsModule() {} | ||
} // namespace worklets |
23 changes: 23 additions & 0 deletions
23
packages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModule.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <cxxreact/MessageQueueThread.h> | ||
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h> | ||
#include <string> | ||
|
||
namespace worklets { | ||
|
||
class NativeWorkletsModule : public NativeWorkletsModuleSpec { | ||
public: | ||
explicit NativeWorkletsModule(const std::string &valueUnpackerCode); | ||
|
||
~NativeWorkletsModule(); | ||
|
||
[[nodiscard]] inline std::string getValueUnpackerCode() const { | ||
return valueUnpackerCode_; | ||
} | ||
|
||
private: | ||
const std::string valueUnpackerCode_; | ||
}; | ||
|
||
} // namespace worklets |
9 changes: 9 additions & 0 deletions
9
...es/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h> | ||
|
||
namespace worklets { | ||
|
||
NativeWorkletsModuleSpec::NativeWorkletsModuleSpec( | ||
const std::shared_ptr<CallInvoker> jsInvoker) | ||
: TurboModule("NativeWorklets", jsInvoker) {} | ||
|
||
} // namespace worklets |
18 changes: 18 additions & 0 deletions
18
...ages/react-native-reanimated/Common/cpp/worklets/NativeModules/NativeWorkletsModuleSpec.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <ReactCommon/CallInvoker.h> | ||
#include <ReactCommon/TurboModule.h> | ||
#include <memory> | ||
|
||
using namespace facebook; | ||
using namespace react; | ||
|
||
namespace worklets { | ||
|
||
class JSI_EXPORT NativeWorkletsModuleSpec : public TurboModule { | ||
protected: | ||
explicit NativeWorkletsModuleSpec( | ||
const std::shared_ptr<CallInvoker> jsInvoker); | ||
}; | ||
|
||
} // namespace worklets |
14 changes: 14 additions & 0 deletions
14
.../react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h> | ||
|
||
namespace worklets { | ||
|
||
void RNRuntimeWorkletDecorator::decorate( | ||
jsi::Runtime &rnRuntime, | ||
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule) { | ||
rnRuntime.global().setProperty( | ||
rnRuntime, | ||
"__workletsModuleProxy", | ||
jsi::Object::createFromHostObject(rnRuntime, nativeWorkletsModule)); | ||
} | ||
|
||
} // namespace worklets |
19 changes: 19 additions & 0 deletions
19
...es/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <jsi/jsi.h> | ||
#include <worklets/NativeModules/NativeWorkletsModule.h> | ||
#include <memory> | ||
|
||
using namespace facebook; | ||
|
||
namespace worklets { | ||
|
||
class RNRuntimeWorkletDecorator { | ||
// TODO: Rename to `RNRuntimeWorkletsDecorator` or something more suitable. | ||
public: | ||
static void decorate( | ||
jsi::Runtime &rnRuntime, | ||
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule); | ||
}; | ||
|
||
} // namespace worklets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.