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

Make the library compatible with react-native-reanimated #67

Closed
wants to merge 1 commit into from

Conversation

xseignard
Copy link

Why

react-native-reanimated is a popular library for react-native to create and drive animations.

See https://docs.swmansion.com/react-native-reanimated/

react-native is running on 2 threads:

  • UI thread for native UI updates
  • JS thread for the react-native code execution

To be able to run simplex-noise on the UI thread with react-native-reanimated we need to workletize the functions.

You can read more here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#worklet

How

Added "worklet" directive where needed.

Test

Tested on mobile with [email protected] and [email protected]

Impacts

  • None for web users
  • None for react-native users not relying on react-native-reanimated
  • react-native users relying on react-native-reanimated can now use simplex-noise to create fancy animations running at stable 60fps 🥳

Good to know

Will only work with [email protected]+

@jwagner
Copy link
Owner

jwagner commented Feb 12, 2024

Hey @xseignard ,

Thanks a lot for the PR. I don't quite understand why simplex-noise.js would need annotations to be used with react-native-reanimated. It seems quite backward that a framework would require arbitrary non standard annotations in every library it is used with.

Isn't it possible to just call simplex-noise.js from a function which is annotated? The docs seem sparse but

Worklet runtimes come with performance.now and console.* methods installed out-of-the-box. Other APIs are not available and need to be injected into the runtime or captured via worklet closure.
Seems to allude to the fact that dependencies can be captured in a closure. I think that would be a better way to go about this.

I would prefer not to have non-standard annotations in the code that are only relevant for a very small subset of users.

@xseignard
Copy link
Author

Thanks for your answer.
I perfectly understand your point of view.

Unfortunately you can only call workletized function within worklets.

I'll try to find another approach to leverage your great lib in react-native projects.

Thanks for your work!

@xseignard xseignard closed this Feb 12, 2024
@jwagner
Copy link
Owner

jwagner commented Feb 12, 2024

Hey Xavier,

I'd hate to give up on this just yet. There must be some sensible way to get this to work. It's just a bit hard for me to experiment without a running react native setup.

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