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

Workletizable Classes #6230

Merged
merged 12 commits into from
Jul 22, 2024
Merged

Workletizable Classes #6230

merged 12 commits into from
Jul 22, 2024

Conversation

tjzel
Copy link
Collaborator

@tjzel tjzel commented Jul 8, 2024

Summary

This pull request features running classes on the Worklet runtime. Classes aren't supported by Hermes and require polyfilling.

  • Class instances can be created in worklets.
  • Class instances cannot be sent between runtimes - afaik it's impossible to create host objects with a prototype.
  • Static class methods aren't supported - a feature for the future perhaps.

Current implementation is a bit naive.

  1. We create worklets from all required polyfills.
  2. We create the whole class (not the class instance!) in the worklet.
  3. We create the instance of this ad-hoc made class.

We could could put the class in the global scope, however it doesn't seem exactly necessary at the moment.

You can obtain a worklet class explicitly by adding a ClassProperty __workletClass to it

// Explicit WorkletClass
class Clazz {
  __workletClass = true;
}

or implicitly by placing it in a file with a worklet directive.

'worklet';
// Implicit WorkletClass
class Clazz {}

Test plan

  • Add unit tests
  • Add runtime tests suite

@tomekzaw tomekzaw self-requested a review July 8, 2024 19:58
Base automatically changed from @tjzel/plugin/context-objects to @tjzel/plugin/allow-file-workletization July 17, 2024 11:28
@tjzel tjzel force-pushed the @tjzel/plugin/allow-file-workletization branch from 4dcf605 to d6fcab1 Compare July 17, 2024 11:29
Base automatically changed from @tjzel/plugin/allow-file-workletization to main July 17, 2024 12:09
@tjzel tjzel changed the base branch from main to @tjzel/plugin/context-objects July 17, 2024 14:15
Base automatically changed from @tjzel/plugin/context-objects to main July 17, 2024 14:47
@tjzel tjzel marked this pull request as ready for review July 18, 2024 11:21
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/class.ts Outdated Show resolved Hide resolved
packages/react-native-reanimated/plugin/src/file.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@bartlomiejbloniarz bartlomiejbloniarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚗

@tjzel tjzel added this pull request to the merge queue Jul 22, 2024
Merged via the queue into main with commit 72b761a Jul 22, 2024
8 checks passed
@tjzel tjzel deleted the @tjzel/plugin/classes branch July 22, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants