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

Autoworkletize callbacks in Layout Animations #4652

Merged

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Jun 30, 2023

Summary

Currently we support auto-workletizing callbacks with method chaining for react-native-gesture-handler:

Gesture.Tap().onBegin(() => {
  // will be automatically workletized
  ...
});

This pull request adds similar functionality to Layout Animations and their withCallback method so the worklet directive is no longer necessary.

FadeIn.duration(400).withCallback(() => {
  // will be automatically workletized now
  ...
});

Test plan

A new test suite was added to plugin's tests.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need also tests for class instance, for example - new FadeIn().withCallback() and for longer chaining like - FadeIn.duration().springify().withCallback(), FadeIn.duration().withCallback().springify()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think tests with new keywords are necessary. Moreover, I think they would be misleading as it's not a case that's in any way considered in our plugin. If we take a look at the AST tree:

Screenshot 2023-07-04 at 10 36 38

Everything is wrapped in NewExpression. So unless babel ever decides to change how it parses the tree we shouldn't worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgor to add () to constructor here, therefore objects with new operator actually have to be handled 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'm just wondering if it is possible to create tests that will check if all names from EntryExitAnimations, LayoutTransitions, BaseAnimationsChainableMethods, and DefaultTransitionChainableMethods are still relevant. I mean, how to detect that someone changes the name of a class/method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to do it but it seems very complicated. TypeScript makes it difficult enough to import (actually require) anything outside plugin's root directory and forces us to use require, therefore we would need to use require on generated lib files 😵

@tjzel tjzel added this pull request to the merge queue Jul 11, 2023
Merged via the queue into main with commit 503157d Jul 11, 2023
1 check passed
@tjzel tjzel deleted the @kacperkapusciak/autoworkletize-withCallback-layout-animations branch July 11, 2023 13:51
Latropos pushed a commit that referenced this pull request Jul 13, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Currently we support auto-workletizing callbacks with method chaining
for `react-native-gesture-handler`:

```TS
Gesture.Tap().onBegin(() => {
  // will be automatically workletized
  ...
});
```

This pull request adds similar functionality to Layout Animations and
their `withCallback` method so the `worklet` directive is no longer
necessary.

```TS
FadeIn.duration(400).withCallback(() => {
  // will be automatically workletized now
  ...
});
```


## Test plan

A new test suite was added to plugin's tests.

---------

Co-authored-by: kacperkapusciak <kacper.kapusciak@swmansion.com>
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.

None yet

3 participants