Get uiRuntime directly from react-native-worklets#4276
Conversation
uiRuntime directly from react-native-worklets
|
|
||
| if(${RNGH_USE_WORKLETS}) | ||
| target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets) | ||
| endif() |
There was a problem hiding this comment.
Can we have a single if(${RNGH_USE_WORKLETS}) block?
| target_include_directories( | ||
| ${PACKAGE_NAME} | ||
| PRIVATE | ||
| "${REACT_NATIVE_DIR}/ReactCommon/jsiexecutor" | ||
| ) |
There was a problem hiding this comment.
Do we need to do that? Maybe there's a target in react native that exposes these headers.
| return rootProject.subprojects.find { it.name == 'react-native-worklets' } != null | ||
| } |
There was a problem hiding this comment.
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>) |
There was a problem hiding this comment.
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?.(() => { |
There was a problem hiding this comment.
| Worklets.scheduleOnUI?.(() => { | |
| Worklets?.scheduleOnUI?.(() => { |
| bool RNGHRuntimeDecorator::installUIRuntimeBindings( | ||
| jsi::Runtime &rnRuntime, | ||
| int moduleId, | ||
| void RNGHRuntimeDecorator::decorateUIRuntime( |
There was a problem hiding this comment.
Hmm, now this is actually what installs the bindings.
| void RNGHRuntimeDecorator::decorateUIRuntime( | |
| void RNGHRuntimeDecorator::installUIRuntimeBindings( |
| uiRuntime, "_setGestureStateSync", std::move(setGestureStateSync)); | ||
| } | ||
|
|
||
| bool RNGHRuntimeDecorator::installUIRuntimeBindings( |
There was a problem hiding this comment.
Maybe rename it to something like
| 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)
| auto moduleIdValue = jsi::Value(moduleId); | ||
| rnRuntime.global().setProperty( | ||
| rnRuntime, "_RNGH_MODULE_ID", std::move(moduleIdValue)); |
There was a problem hiding this comment.
installRNRuntimeBindings already does it, so this shouldn't be needed at all.
Description
The
uiRuntimeaddress is currently accessed through the Reanimated's global_WORKLET_RUNTIMEstored on the main JS thread. This diff changes that to firstly try accessing it using thegetUIWorkletRuntimefromreact-native-worklets( whenever worklets are found) and fallback to previous approach.Test plan
Tested on Runtime Decoration example on iOS and Android.