From 89bf3d8b388d4214a82b4c1485e1f04cfd511bd4 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 24 Jun 2019 19:04:28 -0700 Subject: [PATCH] Allow ReactChoreographer to execute a FrameCallback that removes another FrameCallback from the mCallbackQueues Summary: This diff extends the ReactChoreographer to allow the execution of FrameCallbacks that removes another FrameCallback from the mCallbackQueues. Reviewed By: ejanzer Differential Revision: D15891759 fbshipit-source-id: 62bc2b6afac45c50ac18771b0821742b4f7fc10e --- .../react/modules/core/ReactChoreographer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java index 52fe20f440c..6a8a302a3d0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java @@ -167,10 +167,16 @@ public class ReactChoreographer { synchronized (mCallbackQueuesLock) { mHasPostedCallback = false; for (int i = 0; i < mCallbackQueues.length; i++) { - int initialLength = mCallbackQueues[i].size(); + ArrayDeque callbackQueue = mCallbackQueues[i]; + int initialLength = callbackQueue.size(); for (int callback = 0; callback < initialLength; callback++) { - mCallbackQueues[i].removeFirst().doFrame(frameTimeNanos); - mTotalCallbacks--; + ChoreographerCompat.FrameCallback frameCallback = callbackQueue.pollFirst(); + if (frameCallback != null) { + frameCallback.doFrame(frameTimeNanos); + mTotalCallbacks--; + } else { + FLog.e(ReactConstants.TAG, "Tried to execute non-existent frame callback"); + } } } maybeRemoveFrameCallback();