From ea1ff374de2ece7d1698b14d4e1aa8075df22cdd Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Mon, 12 Apr 2021 09:16:40 -0700 Subject: [PATCH] Assign batch number to only batched animated instructions Summary: Changelog: [Internal] `NativeAnimatedModule` on Android currently enforces all animation operations to be processed in batches to ensure that all associated operations are processed at the same time. Some operations, however, can be triggered outside of the batching calls (e.g. when using `Animated` for tracking touches `PanResponder`), and they are not processed until the next batch. This change tracks if we are currently processing a batch and doesn't assign a batch number if an operation was triggered outside of `startOperationBatch`/`finishOperationBatch` pair. Reviewed By: mdvacca Differential Revision: D27682424 fbshipit-source-id: 2ea8737c353c81557fa586b15aa5760db3e8813f --- .../com/facebook/react/animated/NativeAnimatedModule.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java index dd7a0c1b2f3..9d6f4299db2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -118,6 +118,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec private boolean mBatchingControlledByJS = false; // TODO T71377544: delete private volatile long mCurrentFrameNumber; // TODO T71377544: delete private volatile long mCurrentBatchNumber; + private volatile boolean mIsInBatch = false; private boolean mInitializedForFabric = false; private boolean mInitializedForNonFabric = false; @@ -173,7 +174,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec } private void addOperation(UIThreadOperation operation) { - operation.setBatchNumber(mCurrentBatchNumber); + operation.setBatchNumber(mIsInBatch ? mCurrentBatchNumber : -1); mOperations.add(operation); } @@ -183,7 +184,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec } private void addPreOperation(UIThreadOperation operation) { - operation.setBatchNumber(mCurrentBatchNumber); + operation.setBatchNumber(mIsInBatch ? mCurrentBatchNumber : -1); mPreOperations.add(operation); } @@ -426,12 +427,14 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec @Override public void startOperationBatch() { mBatchingControlledByJS = true; + mIsInBatch = true; mCurrentBatchNumber++; } @Override public void finishOperationBatch() { mBatchingControlledByJS = true; + mIsInBatch = false; mCurrentBatchNumber++; }