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
This commit is contained in:
Andrei Shikov
2021-04-12 09:16:40 -07:00
committed by Facebook GitHub Bot
parent f5502fbda9
commit ea1ff374de
@@ -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++;
}