-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(Worklets): allow passing user-implemented AsyncQueue to createWorkletRuntime #7851
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beat me to it! Wanted to draft something up today but couldn't find the time.
I'll test this tmrw, thanks so much! :)
packages/react-native-worklets/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp
Outdated
Show resolved
Hide resolved
oh btw., we would still need support for capturing const myObj = ...
function worklet() {
'worklet'
myObj.myFunc()
}
Then it'd be ready for a VisionCamera prototype |
Could you elaborate on that? I'm not sure I get it, since you said that myObj is empty but then you invoke |
Yes |
Could you give me a link to the place in the code when you use this pattern? I think I need to understand what's going on to implement that. |
This is how a function on a Nitro HybridObject looks like. It's a myObj.myFunc() ..will be So for Worklets what needs to be done to properly keep this functionality;
|
The simplest way to test this is;
..or just install a Nitro Module like e.g. react-native-unistyles, react-native-nitro-image, react-native-video v7, ... EDIT: Btw the most efficient way of capturing Nitro HybridObjects would be if you guys would actually call the |
I think this is already supported right off the bat, but let me double check it 🙏 |
Yep, I tested it - HostFunction & this and the native state work already. Regarding the #ifdef, I don't mind putting it in the code if it's going to be non-invasive. |
awesome! |
…ts/runtime-async-queue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for passing user-implemented AsyncQueue objects to the createWorkletRuntime
function, fulfilling a feature request from issue #7831. The implementation uses jsi::NativeState
to avoid boilerplate and provides backward compatibility through function overloads.
- Enhanced
createWorkletRuntime
to accept optional custom AsyncQueue implementations - Updated the type system with discriminated unions to ensure proper queue configuration
- Modified the C++ layer to handle custom queue injection through the JSI bridge
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
packages/react-native-worklets/src/runtimes.ts | Added overloads and queue configuration options to createWorkletRuntime |
packages/react-native-worklets/src/WorkletsModule/workletsModuleProxy.ts | Extended interface to include queue parameters |
packages/react-native-worklets/src/WorkletsModule/NativeWorklets.ts | Updated implementation to pass queue parameters through |
packages/react-native-worklets/src/WorkletsModule/JSWorklets.ts | Simplified JSWorklets implementation signature |
packages/react-native-worklets/typetests/createWorkletRuntime.tsx | Added comprehensive type tests for new queue configuration options |
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h | Added queue parameter to constructor and runtime assertion |
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp | Updated constructor to accept and store custom queue |
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h | Extended createWorkletRuntime method signature |
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp | Updated runtime creation to pass custom queue |
packages/react-native-worklets/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp | Added queue extraction logic and parameter handling |
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h
Outdated
Show resolved
Hide resolved
@mrousavy We got it merged 🥳 It will be available in [email protected] soon™! |
super cool!! thanks |
Summary
As requested in #7831. I opted to use
jsi::NativeState
instead ofjsi::HostObject
since it introduces less boilerplate.Test plan