Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Worklets): Create a stub of Worklets Module #6539

Merged
merged 67 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6fef514
feat: Create a stub of Worklets Module
tjzel Sep 23, 2024
3677ce0
chore: Fix linting
tjzel Sep 24, 2024
b37f2d5
chore: Fix codegen
tjzel Sep 24, 2024
bed69c0
chore: Revert implicit capture fix
tjzel Sep 24, 2024
c7e0b0f
chore: Fix codegen
tjzel Sep 24, 2024
a513d82
chore: Revert JSScheduler change
tjzel Sep 24, 2024
a88d4e3
chore: Fix headers
tjzel Sep 25, 2024
6fd5477
chore: Move valueUnpacker code to worklets`
tjzel Sep 25, 2024
c9ec647
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 25, 2024
134658f
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 25, 2024
27ae244
chore: Lint and cleanup
tjzel Sep 25, 2024
6cdaa23
chore: Fix circular deps
tjzel Sep 25, 2024
605ed91
chore: Fix build on tvOS
tjzel Sep 25, 2024
eea2975
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 25, 2024
22793d2
chore: Review changes
tjzel Sep 25, 2024
cf97bdb
chore: Fix typo and old name
tjzel Sep 26, 2024
120791a
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 26, 2024
d5f6ad1
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 27, 2024
87b6dd5
refactor: Merge TypeScript type files
tjzel Sep 27, 2024
9b9731c
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Sep 30, 2024
b78c2e6
refactor: Merge TypeScript type files
tjzel Sep 27, 2024
3c08411
refactor: JavaScript NativeReanimatedModule
tjzel Sep 27, 2024
bfa97b7
chore: Review changes
tjzel Sep 30, 2024
5e6fcde
chore: Whitespace
tjzel Sep 30, 2024
9c5df0d
chore: Gradle paths
tjzel Sep 30, 2024
ea08251
Merge branch 'main' into @tjzel/worklets/javascript-modules-refactor
tjzel Sep 30, 2024
4d4b079
Merge branch '@tjzel/worklets/javascript-modules-refactor' into @tjze…
tjzel Sep 30, 2024
6cecffa
chore: Gradle paths
tjzel Sep 30, 2024
f98b5f7
chore: Update test
tjzel Sep 30, 2024
379db3b
Merge branch 'main' into @tjzel/worklets/javascript-modules-refactor
tjzel Oct 3, 2024
104f412
Merge branch '@tjzel/worklets/javascript-modules-refactor' into @tjze…
tjzel Oct 3, 2024
ee8b249
chore: Merge TS from main
tjzel Oct 3, 2024
df6e91d
Merge branch '@tjzel/worklets/merge-type-files' into @tjzel/worklets/…
tjzel Oct 3, 2024
f9a082c
chore: Update cpp validation scripts
tjzel Oct 4, 2024
8043562
chore: Update cpp validation scripts
tjzel Oct 4, 2024
8ec67d3
chore: Update worklet namespace on Android
tjzel Oct 4, 2024
1f5dacc
chore: Update worklet namespace on iOS
tjzel Oct 4, 2024
d60c781
chore: Update podfile.locks
tjzel Oct 4, 2024
a4eac93
chore: Clean Java part
tjzel Oct 4, 2024
1ad7242
chore: Apply formatting
tjzel Oct 5, 2024
1aa3df2
Merge branch 'main' into @tjzel/worklets/merge-type-files
tjzel Oct 24, 2024
cc92180
Merge branch '@tjzel/worklets/merge-type-files' into @tjzel/worklets/…
tjzel Oct 24, 2024
fdd6648
chore: Add newlines
tjzel Oct 29, 2024
be55b3c
Merge branch '@tjzel/worklets/merge-type-files' into @tjzel/worklets/…
tjzel Oct 29, 2024
aaca06f
Merge branch 'main' into @tjzel/worklets/merge-type-files
tjzel Oct 29, 2024
f9374ff
Merge branch '@tjzel/worklets/merge-type-files' into @tjzel/worklets/…
tjzel Oct 29, 2024
440b1f2
chore: Cleanup
tjzel Oct 29, 2024
d006298
chore: Move apple worklets files to apple dir
tjzel Oct 29, 2024
388f6be
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Oct 29, 2024
071ab8a
chore: Move WorkletsModule outside of source sets
tjzel Oct 30, 2024
27823fb
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Oct 30, 2024
4f17571
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Oct 31, 2024
cf77574
chore: Aggregate commit
tjzel Nov 7, 2024
90cdd1a
chore: Self-review
tjzel Nov 7, 2024
a51223b
chore: Update yarn.lock
tjzel Nov 7, 2024
dde6da4
Merge branch '@tjzel/remove-code-below-74' into @tjzel/worklets/nativ…
tjzel Nov 7, 2024
ea1beed
chore: Fix native state
tjzel Nov 8, 2024
33b64c3
chore: Fix build.gradle
tjzel Nov 10, 2024
710a7d6
Merge branch '@tjzel/remove-code-below-74' into @tjzel/worklets/nativ…
tjzel Nov 11, 2024
75b1b1a
chore: Update podfile.locks
tjzel Nov 11, 2024
4d9c44c
chore: Remove irrelevant changes
tjzel Nov 11, 2024
3026137
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Nov 11, 2024
3c32953
chore: Fix android backwards compatibility
tjzel Nov 11, 2024
7f3bae6
chore: Apply formatting
tjzel Nov 11, 2024
19c318b
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Nov 18, 2024
b306e71
chore: Review changes
tjzel Nov 19, 2024
039fb3c
Merge branch 'main' into @tjzel/worklets/native-worklets-module-stub
tjzel Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,28 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.17.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets/apple (= 3.17.0)
- Yoga
- RNReanimated/worklets/apple (3.17.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -2229,7 +2251,7 @@ SPEC CHECKSUMS:
RNCPicker: b978067931744f5a7316b48b8dcf145d4d722672
RNFlashList: 6f169ad83e52579b7754cbbcec1b004c27d82c93
RNGestureHandler: fc5ce5bf284640d3af6431c3a5c3bc121e98d045
RNReanimated: 2db902281618797873d75426f334ede4e503baf8
RNReanimated: c03f9fdff5fd382d1833c37fa0e6f64ffd9b8a92
RNScreens: 2fe13c8d610ef2d9d5ace2e7d85b716ec0f5217c
RNSVG: 536cd3c866c878faf72beaba166c8b02fe2b762b
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Expand Down
24 changes: 23 additions & 1 deletion apps/macos-example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,28 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.17.0):
- DoubleConversion
- glog
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-jsi
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets/apple (= 3.17.0)
- Yoga
- RNReanimated/worklets/apple (3.17.0):
- DoubleConversion
- glog
- RCT-Folly (= 2024.01.01.00)
Expand Down Expand Up @@ -1843,7 +1865,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: ec53e44dc3e75b44aa2a9f37618a49c3bc080a7a
RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94
RNGestureHandler: 82f59e40580e0c2f8262552c149716511131b412
RNReanimated: 8b9e602d3bc250cfd046c584454aa2a2efa8bd7e
RNReanimated: ed490424d3b8b9f2acd104577c73b374fc79310b
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
SocketRocket: 9ee265c4b5ae2382d18e4ee1d2dd2d7af0ff1ab5
Yoga: a7f65c1fd1394973b9ea40c9c270530e9d7cd2e7
Expand Down
24 changes: 23 additions & 1 deletion apps/paper-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,28 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.17.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets/apple (= 3.17.0)
- Yoga
- RNReanimated/worklets/apple (3.17.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -2019,7 +2041,7 @@ SPEC CHECKSUMS:
RNCPicker: f963e01f78e546a93b98aa201501713dbda14e94
RNFlashList: 115dd44377580761bff386a0caebf165424cf16f
RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8
RNReanimated: 9ef3b1908a15b0b778edd6dacad9c71e7fe9e849
RNReanimated: 1d16252a3b482d884ba83b09800594fbfa773291
RNScreens: de948b09c9a30f3ea52f9840dd6f8ce92b4e33d3
RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Expand Down
24 changes: 23 additions & 1 deletion apps/tvos-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,28 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.17.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets/apple (= 3.17.0)
- Yoga
- RNReanimated/worklets/apple (3.17.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1864,7 +1886,7 @@ SPEC CHECKSUMS:
React-utils: 3fce26d04c6776ddd47f255e7f3adc70d61b4491
ReactCodegen: 61cc9f25250fd53c91d30d82e84a1c6aafcf451a
ReactCommon: b927fd46115bd2acb146e24cf1a08f22abda8b3f
RNReanimated: b007fe1002350dd2ffb10fec214560a167794e12
RNReanimated: 3a5e1e235c940894097b0734aad9ebce45431ddd
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 651e5fd560c7e408ab9d9ca44b8de1b622d7f0cc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,30 @@ using namespace facebook;
namespace reanimated {

NativeReanimatedModule::NativeReanimatedModule(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode,
const bool isBridgeless,
const bool isReducedMotion)
: NativeReanimatedModuleSpec(
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
isBridgeless_(isBridgeless),
isReducedMotion_(isReducedMotion),
jsQueue_(jsQueue),
nativeWorkletsModule_(nativeWorkletsModule),
jsScheduler_(jsScheduler),
uiScheduler_(uiScheduler),
valueUnpackerCode_(nativeWorkletsModule->getValueUnpackerCode()),
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
rnRuntime,
jsQueue,
jsScheduler_,
"Reanimated UI runtime",
true /* supportsLocking */,
valueUnpackerCode)),
valueUnpackerCode_(valueUnpackerCode),
valueUnpackerCode_)),
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
requestRender_(platformDepMethodsHolder.requestRender),
onRenderCallback_([this](const double timestampMs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
#endif // RCT_NEW_ARCH_ENABLED

#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/Registries/EventHandlerRegistry.h>
#include <worklets/Tools/JSScheduler.h>
#include <worklets/Tools/UIScheduler.h>
Expand All @@ -32,12 +33,12 @@ namespace reanimated {
class NativeReanimatedModule : public NativeReanimatedModuleSpec {
public:
NativeReanimatedModule(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode,
const bool isBridgeless,
const bool isReducedMotion);

Expand Down Expand Up @@ -168,18 +169,23 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
return *layoutAnimationsManager_;
}

inline jsi::Runtime &getUIRuntime() const {
[[nodiscard]] inline jsi::Runtime &getUIRuntime() const {
return uiWorkletRuntime_->getJSIRuntime();
}

inline bool isBridgeless() const {
[[nodiscard]] inline bool isBridgeless() const {
tjzel marked this conversation as resolved.
Show resolved Hide resolved
return isBridgeless_;
}

inline bool isReducedMotion() const {
[[nodiscard]] inline bool isReducedMotion() const {
return isReducedMotion_;
}

[[nodiscard]] inline std::shared_ptr<NativeWorkletsModule>
getNativeWorkletsModule() const {
return nativeWorkletsModule_;
}

private:
void commonInit(const PlatformDepMethodsHolder &platformDepMethodsHolder);

Expand All @@ -195,10 +201,11 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const bool isBridgeless_;
const bool isReducedMotion_;
const std::shared_ptr<MessageQueueThread> jsQueue_;
const std::shared_ptr<NativeWorkletsModule> nativeWorkletsModule_;
const std::shared_ptr<JSScheduler> jsScheduler_;
const std::shared_ptr<UIScheduler> uiScheduler_;
const std::string valueUnpackerCode_;
std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
std::string valueUnpackerCode_;

std::unique_ptr<EventHandlerRegistry> eventHandlerRegistry_;
const RequestRenderFunction requestRender_;
Expand Down
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>
tjzel marked this conversation as resolved.
Show resolved Hide resolved

#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),
tjzel marked this conversation as resolved.
Show resolved Hide resolved
valueUnpackerCode_(valueUnpackerCode) {}

NativeWorkletsModule::~NativeWorkletsModule() {}
} // namespace worklets
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
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) {}
tjzel marked this conversation as resolved.
Show resolved Hide resolved

} // namespace worklets
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);
tjzel marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace worklets
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
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
21 changes: 15 additions & 6 deletions packages/react-native-reanimated/RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ Pod::Spec.new do |s|
s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14", :visionos => "1.0" }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.subspec "worklets" do |ss|
ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}"
ss.header_dir = "worklets"
ss.header_mappings_dir = "Common/cpp/worklets"

ss.subspec "apple" do |sss|
# Please be careful with the snakes.
# 🐍🐍🐍
# Thank you for your understanding.
sss.source_files = "apple/worklets/**/*.{mm,h,m}"
sss.header_dir = "worklets"
sss.header_mappings_dir = "apple/worklets"
end
end

s.subspec "reanimated" do |ss|
ss.source_files = "Common/cpp/reanimated/**/*.{cpp,h}"
ss.header_dir = "reanimated"
Expand All @@ -90,12 +105,6 @@ Pod::Spec.new do |s|
end
end

s.subspec "worklets" do |ss|
ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}"
ss.header_dir = "worklets"
ss.header_mappings_dir = "Common/cpp/worklets"
end

gcc_debug_definitions = "$(inherited)"
if !is_release
gcc_debug_definitions << " HERMES_ENABLE_DEBUGGER=1"
Expand Down
Loading
Loading