From 528f97152b7e0a7465c5b5c02e96c2c4306c78fe Mon Sep 17 00:00:00 2001 From: Nicholas Block Date: Tue, 28 Nov 2023 08:57:23 -0800 Subject: [PATCH] Backout - Schedule a Choreographer callback only if there is ongoing animation Summary: caused performace problems with react app Reviewed By: gpalves Differential Revision: D51617862 fbshipit-source-id: 38c0c06dacdd7aa862fd523a7ce136e54ed55fa2 --- .../react/animated/NativeAnimatedModule.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java index cff0a92988a..76749aaff7f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -25,7 +25,6 @@ import com.facebook.react.bridge.UIManager; import com.facebook.react.bridge.UIManagerListener; import com.facebook.react.bridge.WritableMap; import com.facebook.react.common.annotations.VisibleForTesting; -import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.modules.core.ReactChoreographer; import com.facebook.react.uimanager.GuardedFrameCallback; @@ -248,13 +247,14 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec return; } - if (!ReactFeatureFlags.enableOnDemandReactChoreographer - || nodesManager != null && nodesManager.hasActiveAnimations()) { - Assertions.assertNotNull(mReactChoreographer) - .postFrameCallback( - ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE, - mAnimatedFrameCallback); - } + // TODO: Would be great to avoid adding this callback in case there are no active + // animations and no outstanding tasks on the operations queue. Apparently frame + // callbacks can only be posted from the UI thread and therefore we cannot schedule + // them directly from other threads. + Assertions.assertNotNull(mReactChoreographer) + .postFrameCallback( + ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE, + mAnimatedFrameCallback); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -1116,7 +1116,6 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec opsAndArgs.getInt(i++), opsAndArgs.getInt(i++)); break; case OP_CODE_START_ANIMATING_NODE: - enqueueFrameCallback(); animatedNodesManager.startAnimatingNode( opsAndArgs.getInt(i++), opsAndArgs.getInt(i++), opsAndArgs.getMap(i++), null); break;