Skip to content

Get uiRuntime directly from react-native-worklets#4276

Draft
coado wants to merge 4 commits into
mainfrom
@coado/worklets-integration
Draft

Get uiRuntime directly from react-native-worklets#4276
coado wants to merge 4 commits into
mainfrom
@coado/worklets-integration

Conversation

@coado

@coado coado commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description

The uiRuntime address is currently accessed through the Reanimated's global _WORKLET_RUNTIME stored on the main JS thread. This diff changes that to firstly try accessing it using the getUIWorkletRuntime from react-native-worklets( whenever worklets are found) and fallback to previous approach.

Test plan

Tested on Runtime Decoration example on iOS and Android.

@coado coado changed the title Get uiRuntime directly from react-native-worklets Get uiRuntime directly from react-native-worklets Jun 19, 2026

if(${RNGH_USE_WORKLETS})
target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets)
endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have a single if(${RNGH_USE_WORKLETS}) block?

Comment on lines +50 to +54
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${REACT_NATIVE_DIR}/ReactCommon/jsiexecutor"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to do that? Maybe there's a target in react native that exposes these headers.

Comment on lines +111 to +112
return rootProject.subprojects.find { it.name == 'react-native-worklets' } != null
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also validate worklets' version, or does it work with each one published so far?

0.8.0 may be a good cutoff candidate since it introduces a stable api: software-mansion/react-native-reanimated#8996


#import "RNGHRuntimeDecorator.h"

#if __has_include(<worklets/apple/WorkletsModule.h>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you tried using different linking methods (static/dynamic)?


// Make sure worklets are initialized before attempting to install UI runtime bindings
Worklets?.scheduleOnUI(() => {
Worklets.scheduleOnUI?.(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Worklets.scheduleOnUI?.(() => {
Worklets?.scheduleOnUI?.(() => {

bool RNGHRuntimeDecorator::installUIRuntimeBindings(
jsi::Runtime &rnRuntime,
int moduleId,
void RNGHRuntimeDecorator::decorateUIRuntime(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, now this is actually what installs the bindings.

Suggested change
void RNGHRuntimeDecorator::decorateUIRuntime(
void RNGHRuntimeDecorator::installUIRuntimeBindings(

uiRuntime, "_setGestureStateSync", std::move(setGestureStateSync));
}

bool RNGHRuntimeDecorator::installUIRuntimeBindings(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe rename it to something like

Suggested change
bool RNGHRuntimeDecorator::installUIRuntimeBindings(
bool RNGHRuntimeDecorator::tryFindUIRuntime(

change it to return the runtime (or null), and then in the modules, do

uiRuntime = tryFindUIRuntime(rnRuntime)
installUIRuntimeBindings(uiRuntime)

Comment on lines 138 to 140
auto moduleIdValue = jsi::Value(moduleId);
rnRuntime.global().setProperty(
rnRuntime, "_RNGH_MODULE_ID", std::move(moduleIdValue));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

installRNRuntimeBindings already does it, so this shouldn't be needed at all.

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