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: duplicate worklets code the smart way #6827

Merged
merged 42 commits into from
Jan 29, 2025

Conversation

tjzel
Copy link
Collaborator

@tjzel tjzel commented Dec 17, 2024

Summary

In the transitional period of react-native-worklets coming as a separate package, Reanimated should work with or without react-native-worklets installed. This requires the code of Worklets to be present both in react-native-reanimated and react-native-worklets.

This PR moves Worklets' files that were in Reanimated to react-native-worklets package and adds a script that makes hard links to these files. The linking happens during the yarn build step of react-native-reanimated - this guarantees that react-native-reanimated would still work without react-native-worklets and that its' npm package would still contain all the necessary files.

For Android some files had to be duplicated. This is because of codegen conflicts and namespace generation. However, that code is relatively small and put into respective source sets externalWorklets/with and externalWorklets/without.

Also:

  • I moved ReanimatedVersion.cpp/h files back to Reanimated. We'll implement version checking for Worklets when we actually need it.
  • I adjusted the CI to always do yarn build in Reanimated when necessary.
  • Enabled detection of react-native-worklets in react-native-reanimated.
  • I improved the detection mechanism of react-native-worklets for iOS.
  • Renamed NativeWorkletsModuleSpec.ts to NativeReaWorkletsModuleSpec.ts to avoid codegen conflicts.
  • Removed DummyWorkletsModule from react-native-worklets since now it has WorkletsModule.

Test plan

Run an Example with these changes.

Then do yarn add react-native-worklets in common-app (it will use workspace version by default) in the example directory and run it again.

@tjzel tjzel force-pushed the @tjzel/worklets/restructure-worklets-source-sets branch from b30c495 to 2634199 Compare January 20, 2025 17:33
@tjzel tjzel force-pushed the @tjzel/worklets/duplicate-reanimated-code branch from d723ecc to 62c9488 Compare January 21, 2025 09:02
@tjzel tjzel marked this pull request as ready for review January 21, 2025 11:15
Base automatically changed from @tjzel/worklets/restructure-worklets-source-sets to main January 28, 2025 11:34
@tjzel tjzel added this pull request to the merge queue Jan 29, 2025
Merged via the queue into main with commit 1c66e51 Jan 29, 2025
21 checks passed
@tjzel tjzel deleted the @tjzel/worklets/duplicate-reanimated-code branch January 29, 2025 13:42
github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2025
## Summary

In this PR I'm moving the `WorkletsModule` part of the JS code to
`react-native-worklets`. Reanimated would still have those files
duplicated via a mechanism introduced in #6827.
Now in Reanimated all worklets code must be acquired via a special
`WorkletsResolver` module. This is a temporary solution and will be
dropped once we require `react-native-worklets` as a mandatory
dependency for `react-native-reanimated`.

- Added a workaround so that in our monorepo `react-native-worklets`
wouldn't be used in the app even though it's not a dependency.
- Added an ESLint rule that enforces imports from `WorkletsResolver`.
- I duplicated `PlatformChecker.ts` explicitly in
`react-native-worklets`. This file is small and stable so I don't
consider this to be an issue. We can think of some better solution once
the package is more polished.
- Split some types from `commonTypes.ts` between packages.


## Test plan

Fabric example should work with & without `react-native-worklets`
installed. You can check using the debugger that always the correct
instance of Worklets' JavaScript code is used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants