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 89cf5c36aab..7d9c6421171 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -133,9 +133,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec @UiThread void executeBatch(long maxBatchNumber, NativeAnimatedNodesManager nodesManager) { - List operations; - if (mSynchronizedAccess) { synchronized (this) { operations = drainQueueIntoList(maxBatchNumber); @@ -143,13 +141,19 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec } else { operations = drainQueueIntoList(maxBatchNumber); } - for (UIThreadOperation operation : operations) { - operation.execute(nodesManager); + if (operations != null) { + for (UIThreadOperation operation : operations) { + operation.execute(nodesManager); + } } } @UiThread - private List drainQueueIntoList(long maxBatchNumber) { + private @Nullable List drainQueueIntoList(long maxBatchNumber) { + if (mQueue.isEmpty() && mPeekedOperation == null) { + return null; + } + List operations = new ArrayList<>(); while (true) { // Due to a race condition, we manually "carry-over" a polled item from previous batch diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java index 240c0e203dc..ca2e85ac26e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java @@ -356,13 +356,16 @@ public class MountItemDispatcher { @Nullable private static List drainConcurrentItemQueue( ConcurrentLinkedQueue queue) { + if (queue.isEmpty()) { + return null; + } List result = new ArrayList<>(); - while (!queue.isEmpty()) { + do { E item = queue.poll(); if (item != null) { result.add(item); } - } + } while (!queue.isEmpty()); if (result.size() == 0) { return null; }