From d0e402f3d920c322c36562fa78ccc3dcefbd6130 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 3 Jun 2025 04:43:35 -0700 Subject: [PATCH] Call onRender inline instead of from startRenderCallbackIfNeeded (#51750) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51750 changelog: [internal] inline call `onRender()` instead of calling it from `startRenderCallbackIfNeeded`. This has identical functionality but allows to use Fantom to test C++ Animated. In Fantom, there is only one thread the existing mechanism in C++ Animated uses thread locals to capture which thread in the UI thread. Therefore, some assumptions are broken. This is just an easy workaround around the problem. Reviewed By: javache, zeyap Differential Revision: D75787084 fbshipit-source-id: 8d70ef2d13e4ab14807deb7ca4cb0844980f5901 --- .../animated/NativeAnimatedNodesManager.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp index 9b4e658fdd8..20870546ecb 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp @@ -404,6 +404,12 @@ void NativeAnimatedNodesManager::handleAnimatedEvent( // `startRenderCallbackIfNeeded` will call platform specific code to // register UI tick listener. startRenderCallbackIfNeeded(); + // Calling startOnRenderCallback_ will register a UI tick listener. + // The UI ticker listener will not be called until the next frame. + // That's why, in case this is called from the UI thread, we need to + // proactivelly trigger the animation loop to avoid showing stale + // frames. + onRender(); } } } @@ -426,14 +432,6 @@ NativeAnimatedNodesManager::ensureEventEmitterListener() noexcept { void NativeAnimatedNodesManager::startRenderCallbackIfNeeded() { if (startOnRenderCallback_) { startOnRenderCallback_([this]() { onRender(); }); - - if (isOnRenderThread_) { - // Calling startOnRenderCallback_ will register a UI tick listener. - // The UI ticker listener will not be called until the next frame. - // That's why, in case this is called from the UI thread, we need to - // proactivelly trigger the animation loop to avoid showing stale frames. - onRender(); - } } }