-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Get uiRuntime directly from react-native-worklets
#4276
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
base: main
Are you sure you want to change the base?
Changes from all commits
85194cf
bb38d49
3f1f1fb
d4760a6
9bdf85f
e95ef67
9200d64
2227896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
| #include "RNGestureHandlerModule.h" | ||
|
|
||
| #ifdef RNGH_USE_WORKLETS | ||
| #include <worklets/Compat/StableApi.h> | ||
| #endif | ||
|
|
||
| namespace gesturehandler { | ||
| using namespace facebook; | ||
| using namespace facebook::react; | ||
|
|
@@ -20,7 +24,8 @@ void RNGestureHandlerModule::registerNatives() { | |
| "getBindingsInstallerCxx", | ||
| RNGestureHandlerModule::getBindingsInstallerCxx), | ||
| makeNativeMethod( | ||
| "decorateUIRuntime", RNGestureHandlerModule::decorateUIRuntime), | ||
| "installUIRuntimeBindingsNative", | ||
| RNGestureHandlerModule::installUIRuntimeBindings), | ||
| makeNativeMethod( | ||
| "invalidateNative", RNGestureHandlerModule::invalidateNative)}); | ||
| } | ||
|
|
@@ -51,11 +56,38 @@ void RNGestureHandlerModule::setGestureState( | |
| method(this->javaPart_, handlerTag, state); | ||
| } | ||
|
|
||
| bool RNGestureHandlerModule::decorateUIRuntime() { | ||
| return RNGHRuntimeDecorator::installUIRuntimeBindings( | ||
| *rnRuntime_, getModuleId(), [&](int handlerTag, int state) { | ||
| bool RNGestureHandlerModule::installUIRuntimeBindings() { | ||
| jsi::Runtime *uiRuntime = nullptr; | ||
|
|
||
| #ifdef RNGH_USE_WORKLETS | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| std::shared_ptr<worklets::WorkletRuntime> uiWorkletRuntime; | ||
| const auto runtimeHolder = rnRuntime_->global().getProperty( | ||
| *rnRuntime_, "__RNGH_UI_WORKLET_RUNTIME_HOLDER"); | ||
|
|
||
| if (runtimeHolder.isObject()) { | ||
| uiWorkletRuntime = worklets::getWorkletRuntimeFromHolder( | ||
| *rnRuntime_, runtimeHolder.asObject(*rnRuntime_)); | ||
|
|
||
| if (uiWorkletRuntime) { | ||
| uiRuntime = &worklets::getJSIRuntimeFromWorkletRuntime(uiWorkletRuntime); | ||
| } | ||
| } | ||
| #endif | ||
|
Comment on lines
+60
to
+75
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this a part of |
||
|
|
||
| if (uiRuntime == nullptr) { | ||
| uiRuntime = RNGHRuntimeDecorator::tryFindUIRuntime(*rnRuntime_); | ||
| } | ||
|
|
||
| if (uiRuntime == nullptr) { | ||
| return false; | ||
| } | ||
|
Comment on lines
+77
to
+83
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be the one example when nesting these |
||
|
|
||
| RNGHRuntimeDecorator::installUIRuntimeBindings( | ||
| *uiRuntime, [&](int handlerTag, int state) { | ||
| this->setGestureState(handlerTag, state); | ||
| }); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void RNGestureHandlerModule::invalidateNative() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,10 @@ | |
|
|
||
| #import "RNGHRuntimeDecorator.h" | ||
|
|
||
| #ifdef RNGH_USE_WORKLETS | ||
| #include <worklets/Compat/StableApi.h> | ||
| #endif | ||
|
|
||
| #import "RNGestureHandler.h" | ||
| #import "RNGestureHandlerDirection.h" | ||
| #import "RNGestureHandlerState.h" | ||
|
|
@@ -104,16 +108,40 @@ - (void)initialize | |
| _operations = [NSMutableArray new]; | ||
| } | ||
|
|
||
| - (bool)decorateUIRuntime | ||
| - (bool)tryInstallUIRuntimeBindings | ||
| { | ||
| __weak RNGestureHandlerModule *weakSelf = self; | ||
| jsi::Runtime *uiRuntime = nullptr; | ||
|
|
||
| #ifdef RNGH_USE_WORKLETS | ||
| std::shared_ptr<worklets::WorkletRuntime> uiWorkletRuntime; | ||
| const auto runtimeHolder = _rnRuntime->global().getProperty(*_rnRuntime, "__RNGH_UI_WORKLET_RUNTIME_HOLDER"); | ||
|
|
||
| if (runtimeHolder.isObject()) { | ||
| uiWorkletRuntime = worklets::getWorkletRuntimeFromHolder(*_rnRuntime, runtimeHolder.asObject(*_rnRuntime)); | ||
|
|
||
| if (uiWorkletRuntime != nullptr) { | ||
| uiRuntime = &worklets::getJSIRuntimeFromWorkletRuntime(uiWorkletRuntime); | ||
| } | ||
| } | ||
| #endif | ||
|
Comment on lines
+117
to
+127
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this |
||
|
|
||
| return RNGHRuntimeDecorator::installUIRuntimeBindings(*_rnRuntime, _moduleId, [weakSelf](int handlerTag, int state) { | ||
| if (uiRuntime == nullptr) { | ||
| uiRuntime = RNGHRuntimeDecorator::tryFindUIRuntime(*_rnRuntime); | ||
| } | ||
|
|
||
| if (uiRuntime == nullptr) { | ||
| return false; | ||
| } | ||
|
|
||
| RNGHRuntimeDecorator::installUIRuntimeBindings(*uiRuntime, [weakSelf](int handlerTag, int state) { | ||
| RNGestureHandlerModule *strongSelf = weakSelf; | ||
| if (strongSelf != nil) { | ||
| [strongSelf setGestureState:state forHandler:handlerTag]; | ||
| } | ||
| }); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| - (void)createGestureHandler:(NSString *)handlerName handlerTag:(double)handlerTag config:(NSDictionary *)config | ||
|
|
@@ -185,7 +213,7 @@ - (void)flushOperations | |
| - (nonnull NSNumber *)installUIRuntimeBindings | ||
| { | ||
| if (!_uiRuntimeDecorated) { | ||
| _uiRuntimeDecorated = [self decorateUIRuntime]; | ||
| _uiRuntimeDecorated = [self tryInstallUIRuntimeBindings]; | ||
| } | ||
|
|
||
| return _uiRuntimeDecorated ? @1 : @0; | ||
|
|
||
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.
Why is this needed?
Other lib checks don't have this, maybe it would be possible to fold it into
getExternalLibVersionif necessary?