Skip to content

Commit

Permalink
Remove runtime refference from requestRender
Browse files Browse the repository at this point in the history
  • Loading branch information
piaskowyk committed Jan 29, 2025
1 parent b9fcec9 commit 13049e6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,7 @@ void ReanimatedModuleProxy::requestAnimationFrame(
void ReanimatedModuleProxy::maybeRequestRender() {
if (!renderRequested_) {
renderRequested_ = true;
jsi::Runtime &uiRuntime =
workletsModuleProxy_->getUIWorkletRuntime()->getJSIRuntime();
requestRender_(onRenderCallback_, uiRuntime);
requestRender_(onRenderCallback_);
}
}

Expand Down Expand Up @@ -767,18 +765,12 @@ void ReanimatedModuleProxy::cssLoopCallback(const double /*timestampMs*/) {
|| updatesRegistryManager_->hasPropsToRevert()
#endif // ANDROID
) {
jsi::Runtime &rt =
workletsModuleProxy_->getUIWorkletRuntime()->getJSIRuntime();
requestRender_(
[weakThis = weak_from_this()](const double newTimestampMs) {
auto strongThis = weakThis.lock();
if (!strongThis) {
return;
if (auto strongThis = weakThis.lock()) {
strongThis->cssLoopCallback(newTimestampMs);
}

strongThis->cssLoopCallback(newTimestampMs);
},
rt);
});
} else {
cssLoopRunning_ = false;
}
Expand All @@ -797,20 +789,12 @@ void ReanimatedModuleProxy::maybeRunCSSLoop() {
if (!strongThis) {
return;
}

jsi::Runtime &rt =
strongThis->workletsModuleProxy_->getUIWorkletRuntime()
->getJSIRuntime();
strongThis->requestRender_(
[weakThis](const double timestampMs) {
auto strongThis = weakThis.lock();
if (!strongThis) {
return;
if (auto strongThis = weakThis.lock()) {
strongThis->cssLoopCallback(timestampMs);
}

strongThis->cssLoopCallback(timestampMs);
},
rt);
});
});
}

Expand Down Expand Up @@ -918,18 +902,12 @@ void ReanimatedModuleProxy::performOperations() {
}

void ReanimatedModuleProxy::requestFlushRegistry() {
jsi::Runtime &rt =
workletsModuleProxy_->getUIWorkletRuntime()->getJSIRuntime();
requestRender_(
[weakThis = weak_from_this()](double time) {
auto strongThis = weakThis.lock();
if (!strongThis) {
return;
if (auto strongThis = weakThis.lock()) {
strongThis->shouldFlushRegistry_ = true;
}

strongThis->shouldFlushRegistry_ = true;
},
rt);
});
}

void ReanimatedModuleProxy::commitUpdates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ using ObtainPropFunction =
#endif // RCT_NEW_ARCH_ENABLED

using RequestRenderFunction =
std::function<void(std::function<void(const double)>, jsi::Runtime &)>;
std::function<void(std::function<void(const double)>)>;
using GetAnimationTimestampFunction = std::function<double(void)>;

using ProgressLayoutAnimationFunction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ void NativeProxy::registerNatives() {
makeNativeMethod("invalidateCpp", NativeProxy::invalidateCpp)});
}

void NativeProxy::requestRender(
std::function<void(double)> onRender,
jsi::Runtime &) {
void NativeProxy::requestRender(std::function<void(double)> onRender) {
static const auto method =
getJniMethod<void(AnimationFrameCallback::javaobject)>("requestRender");
method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class NativeProxy : public jni::HybridClass<NativeProxy>,
const int emitterReactTag);
void performOperations();
bool getIsReducedMotion();
void requestRender(std::function<void(double)> onRender, jsi::Runtime &rt);
void requestRender(std::function<void(double)> onRender);
void registerEventHandler();
void maybeFlushUIUpdatesQueue();
void setGestureState(int handlerTag, int newState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ SetGestureStateFunction makeSetGestureStateFunctionBridgeless(RCTModuleRegistry

RequestRenderFunction makeRequestRender(REANodesManager *nodesManager)
{
auto requestRender = [nodesManager](std::function<void(double)> onRender, jsi::Runtime &rt) {
auto requestRender = [nodesManager](std::function<void(double)> onRender) {
[nodesManager postOnAnimation:^(READisplayLink *displayLink) {
#if !TARGET_OS_OSX
auto targetTimestamp = displayLink.targetTimestamp;
#else
// TODO macOS targetTimestamp isn't available on macOS
auto targetTimestamp = displayLink.timestamp + displayLink.duration;
#endif
double frameTimestamp =

(targetTimestamp) * 1000;
const double frameTimestamp = targetTimestamp * 1000;
onRender(frameTimestamp);
}];
};
Expand Down

0 comments on commit 13049e6

Please sign in to comment.