Remove ChoreographerCompat (#39775)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39775

ChoreographerCompat existed to support JellyBean, but given we target Android SDK 23+ now, this is safe to remove.

Changelog: [Android][Removed] Deprecated ChoreographerCompat.FrameCallback, use Choreographer.FrameCallback

Reviewed By: mdvacca

Differential Revision: D49826889

fbshipit-source-id: 5158c470553327b70a199168f5b7ed7071cc8c48
This commit is contained in:
Pieter De Baets
2023-10-03 08:00:16 -07:00
committed by Facebook GitHub Bot
parent 0e10ee6ac6
commit 248c324cca
14 changed files with 116 additions and 237 deletions
@@ -9,10 +9,11 @@ package com.facebook.react.testing.idledetection;
import android.app.Instrumentation;
import android.os.SystemClock;
import android.view.Choreographer;
import androidx.test.InstrumentationRegistry;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -48,26 +49,24 @@ public class ReactIdleDetectionUtil {
final int waitFrameCount = 2;
final CountDownLatch latch = new CountDownLatch(1);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
final ChoreographerCompat choreographerCompat = ChoreographerCompat.getInstance();
choreographerCompat.postFrameCallback(
new ChoreographerCompat.FrameCallback() {
() -> {
ReactChoreographer choreographer = ReactChoreographer.getInstance();
choreographer.postFrameCallback(
ReactChoreographer.CallbackType.IDLE_EVENT,
new Choreographer.FrameCallback() {
private int frameCount = 0;
private int frameCount = 0;
@Override
public void doFrame(long frameTimeNanos) {
frameCount++;
if (frameCount == waitFrameCount) {
latch.countDown();
} else {
choreographerCompat.postFrameCallback(this);
}
@Override
public void doFrame(long frameTimeNanos) {
frameCount++;
if (frameCount == waitFrameCount) {
latch.countDown();
} else {
choreographer.postFrameCallback(
ReactChoreographer.CallbackType.IDLE_EVENT, this);
}
});
}
}
});
});
try {
if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
@@ -7,12 +7,12 @@
package com.facebook.react.fabric;
import android.view.Choreographer;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.JSExceptionHandler;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.core.ChoreographerCompat;
public abstract class GuardedFrameCallback extends ChoreographerCompat.FrameCallback {
public abstract class GuardedFrameCallback implements Choreographer.FrameCallback {
@NonNull private final JSExceptionHandler mExceptionHandler;
@@ -5,107 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
// This file was pulled from the facebook/rebound repository.
package com.facebook.react.modules.core;
import android.os.Handler;
import android.view.Choreographer;
import com.facebook.react.bridge.UiThreadUtil;
/**
* Wrapper class for abstracting away availability of the JellyBean Choreographer. If Choreographer
* is unavailable we fallback to using a normal Handler.
*/
public class ChoreographerCompat {
private static final long ONE_FRAME_MILLIS = 17;
private static ChoreographerCompat sInstance;
private Handler mHandler;
private Choreographer mChoreographer;
public static ChoreographerCompat getInstance() {
UiThreadUtil.assertOnUiThread();
if (sInstance == null) {
sInstance = new ChoreographerCompat();
}
return sInstance;
}
private ChoreographerCompat() {
mChoreographer = getChoreographer();
}
public void postFrameCallback(FrameCallback callbackWrapper) {
choreographerPostFrameCallback(callbackWrapper.getFrameCallback());
}
public void postFrameCallbackDelayed(FrameCallback callbackWrapper, long delayMillis) {
choreographerPostFrameCallbackDelayed(callbackWrapper.getFrameCallback(), delayMillis);
}
public void removeFrameCallback(FrameCallback callbackWrapper) {
choreographerRemoveFrameCallback(callbackWrapper.getFrameCallback());
}
private Choreographer getChoreographer() {
return Choreographer.getInstance();
}
private void choreographerPostFrameCallback(Choreographer.FrameCallback frameCallback) {
mChoreographer.postFrameCallback(frameCallback);
}
private void choreographerPostFrameCallbackDelayed(
Choreographer.FrameCallback frameCallback, long delayMillis) {
mChoreographer.postFrameCallbackDelayed(frameCallback, delayMillis);
}
private void choreographerRemoveFrameCallback(Choreographer.FrameCallback frameCallback) {
mChoreographer.removeFrameCallback(frameCallback);
}
/**
* This class provides a compatibility wrapper around the JellyBean FrameCallback with methods to
* access cached wrappers for submitting a real FrameCallback to a Choreographer or a Runnable to
* a Handler.
*/
public abstract static class FrameCallback {
private Runnable mRunnable;
private Choreographer.FrameCallback mFrameCallback;
Choreographer.FrameCallback getFrameCallback() {
if (mFrameCallback == null) {
mFrameCallback =
new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
FrameCallback.this.doFrame(frameTimeNanos);
}
};
}
return mFrameCallback;
}
Runnable getRunnable() {
if (mRunnable == null) {
mRunnable =
new Runnable() {
@Override
public void run() {
doFrame(System.nanoTime());
}
};
}
return mRunnable;
}
/**
* Just a wrapper for frame callback, see {@link
* android.view.Choreographer.FrameCallback#doFrame(long)}.
*/
public abstract void doFrame(long frameTimeNanos);
}
/** @deprecated Use Choreographer.FrameCallback instead */
@Deprecated
public abstract static class FrameCallback implements Choreographer.FrameCallback {}
}
@@ -8,6 +8,7 @@
package com.facebook.react.modules.core;
import android.util.SparseArray;
import android.view.Choreographer;
import androidx.annotation.Nullable;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Arguments;
@@ -51,7 +52,7 @@ public class JavaTimerManager {
}
}
private class TimerFrameCallback extends ChoreographerCompat.FrameCallback {
private class TimerFrameCallback implements Choreographer.FrameCallback {
// Temporary map for constructing the individual arrays of timers to call
private @Nullable WritableArray mTimersToCall = null;
@@ -89,7 +90,7 @@ public class JavaTimerManager {
}
}
private class IdleFrameCallback extends ChoreographerCompat.FrameCallback {
private class IdleFrameCallback implements Choreographer.FrameCallback {
@Override
public void doFrame(long frameTimeNanos) {
@@ -7,7 +7,7 @@
package com.facebook.react.modules.core;
import androidx.annotation.GuardedBy;
import android.view.Choreographer;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
@@ -17,10 +17,10 @@ import java.util.ArrayDeque;
/**
* A simple wrapper around Choreographer that allows us to control the order certain callbacks are
* executed within a given frame. The main difference is that we enforce this is accessed from the
* UI thread: this is because this ordering cannot be guaranteed across multiple threads.
* executed within a given frame. The wrapped Choreographer instance will always be the main thread
* one and the API's are safe to use from any thread.
*/
public class ReactChoreographer {
public final class ReactChoreographer {
public enum CallbackType {
@@ -67,37 +67,65 @@ public class ReactChoreographer {
}
// This needs to be volatile due to double checked locking issue - https://fburl.com/z409owpf
private @Nullable volatile ChoreographerCompat mChoreographer;
private final ReactChoreographerDispatcher mReactChoreographerDispatcher;
private final Object mCallbackQueuesLock = new Object();
private @Nullable volatile Choreographer mChoreographer;
@GuardedBy("mCallbackQueuesLock")
private final ArrayDeque<ChoreographerCompat.FrameCallback>[] mCallbackQueues;
private final ArrayDeque<Choreographer.FrameCallback>[] mCallbackQueues;
private final Choreographer.FrameCallback mFrameCallback =
new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
synchronized (mCallbackQueues) {
// Callbacks run once and are then automatically removed, the callback will
// be posted again from postFrameCallback
mHasPostedCallback = false;
for (int i = 0; i < mCallbackQueues.length; i++) {
ArrayDeque<Choreographer.FrameCallback> callbackQueue = mCallbackQueues[i];
int initialLength = callbackQueue.size();
for (int callback = 0; callback < initialLength; callback++) {
Choreographer.FrameCallback frameCallback = callbackQueue.pollFirst();
if (frameCallback != null) {
frameCallback.doFrame(frameTimeNanos);
mTotalCallbacks--;
} else {
FLog.e(ReactConstants.TAG, "Tried to execute non-existent frame callback");
}
}
}
maybeRemoveFrameCallback();
}
}
};
private int mTotalCallbacks = 0;
private boolean mHasPostedCallback = false;
private ReactChoreographer() {
mReactChoreographerDispatcher = new ReactChoreographerDispatcher();
mCallbackQueues = new ArrayDeque[CallbackType.values().length];
for (int i = 0; i < mCallbackQueues.length; i++) {
mCallbackQueues[i] = new ArrayDeque<>();
}
initializeChoreographer(null);
UiThreadUtil.runOnUiThread(
() -> {
mChoreographer = Choreographer.getInstance();
});
}
public void postFrameCallback(
CallbackType type, ChoreographerCompat.FrameCallback frameCallback) {
synchronized (mCallbackQueuesLock) {
public void postFrameCallback(CallbackType type, Choreographer.FrameCallback frameCallback) {
synchronized (mCallbackQueues) {
mCallbackQueues[type.getOrder()].addLast(frameCallback);
mTotalCallbacks++;
Assertions.assertCondition(mTotalCallbacks > 0);
if (!mHasPostedCallback) {
if (mChoreographer == null) {
initializeChoreographer(
new Runnable() {
@Override
public void run() {
// Schedule on the main thread, at which point the constructor's async work will have
// completed
UiThreadUtil.runOnUiThread(
() -> {
synchronized (mCallbackQueues) {
postFrameCallbackOnChoreographer();
}
});
@@ -110,33 +138,15 @@ public class ReactChoreographer {
/**
* This method writes on mHasPostedCallback and it should be called from another method that has
* the lock mCallbackQueuesLock
* the lock mCallbackQueues
*/
private void postFrameCallbackOnChoreographer() {
mChoreographer.postFrameCallback(mReactChoreographerDispatcher);
mChoreographer.postFrameCallback(mFrameCallback);
mHasPostedCallback = true;
}
public void initializeChoreographer(@Nullable final Runnable runnable) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
synchronized (ReactChoreographer.class) {
if (mChoreographer == null) {
mChoreographer = ChoreographerCompat.getInstance();
}
}
if (runnable != null) {
runnable.run();
}
}
});
}
public void removeFrameCallback(
CallbackType type, ChoreographerCompat.FrameCallback frameCallback) {
synchronized (mCallbackQueuesLock) {
public void removeFrameCallback(CallbackType type, Choreographer.FrameCallback frameCallback) {
synchronized (mCallbackQueues) {
if (mCallbackQueues[type.getOrder()].removeFirstOccurrence(frameCallback)) {
mTotalCallbacks--;
maybeRemoveFrameCallback();
@@ -148,39 +158,15 @@ public class ReactChoreographer {
/**
* This method reads and writes on mHasPostedCallback and it should be called from another method
* that already has the lock mCallbackQueuesLock.
* that already has the lock on mCallbackQueues.
*/
private void maybeRemoveFrameCallback() {
Assertions.assertCondition(mTotalCallbacks >= 0);
if (mTotalCallbacks == 0 && mHasPostedCallback) {
if (mChoreographer != null) {
mChoreographer.removeFrameCallback(mReactChoreographerDispatcher);
mChoreographer.removeFrameCallback(mFrameCallback);
}
mHasPostedCallback = false;
}
}
private class ReactChoreographerDispatcher extends ChoreographerCompat.FrameCallback {
@Override
public void doFrame(long frameTimeNanos) {
synchronized (mCallbackQueuesLock) {
mHasPostedCallback = false;
for (int i = 0; i < mCallbackQueues.length; i++) {
ArrayDeque<ChoreographerCompat.FrameCallback> callbackQueue = mCallbackQueues[i];
int initialLength = callbackQueue.size();
for (int callback = 0; callback < initialLength; callback++) {
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();
}
}
}
}
@@ -7,10 +7,10 @@
package com.facebook.react.modules.debug;
import android.view.Choreographer;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.bridge.ReactBridge;
import com.facebook.react.common.LongArray;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
@@ -18,7 +18,7 @@ import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugL
* Debug object that listens to bridge busy/idle events and UiManagerModule dispatches and uses it
* to calculate whether JS was able to update the UI during a given frame. After being installed on
* a {@link ReactBridge} and a {@link UIManagerModule}, {@link #getDidJSHitFrameAndCleanup} should
* be called once per frame via a {@link ChoreographerCompat.FrameCallback}.
* be called once per frame via a {@link Choreographer.FrameCallback}.
*/
public class DidJSUpdateUiDuringFrameDetector
implements NotThreadSafeBridgeIdleDebugListener, NotThreadSafeViewHierarchyUpdateDebugListener {
@@ -57,7 +57,7 @@ public class DidJSUpdateUiDuringFrameDetector
}
/**
* Designed to be called from a {@link ChoreographerCompat.FrameCallback#doFrame} call.
* Designed to be called from a {@link Choreographer.FrameCallback#doFrame} call.
*
* <p>There are two 'success' cases that will cause {@link #getDidJSHitFrameAndCleanup} to return
* true for a given frame:
@@ -7,11 +7,11 @@
package com.facebook.react.modules.debug;
import android.view.Choreographer;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.uimanager.UIManagerModule;
import java.util.Map;
import java.util.TreeMap;
@@ -26,7 +26,7 @@ import java.util.TreeMap;
* idle and not trying to update the UI. This is different from the FPS above since JS rendering is
* async.
*/
public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
public class FpsDebugFrameCallback implements Choreographer.FrameCallback {
public static class FpsInfo {
@@ -58,7 +58,7 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
private static final double EXPECTED_FRAME_TIME = 16.9;
private @Nullable ChoreographerCompat mChoreographer;
private @Nullable Choreographer mChoreographer;
private final ReactContext mReactContext;
private final UIManagerModule mUIManagerModule;
private final DidJSUpdateUiDuringFrameDetector mDidJSUpdateUiDuringFrameDetector;
@@ -113,6 +113,7 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
mTimeToFps.put(System.currentTimeMillis(), info);
}
mExpectedNumFramesPrev = expectedNumFrames;
if (mChoreographer != null) {
mChoreographer.postFrameCallback(this);
}
@@ -123,14 +124,10 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
.getCatalystInstance()
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector);
final FpsDebugFrameCallback fpsDebugFrameCallback = this;
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mChoreographer = ChoreographerCompat.getInstance();
mChoreographer.postFrameCallback(fpsDebugFrameCallback);
}
() -> {
mChoreographer = Choreographer.getInstance();
mChoreographer.postFrameCallback(this);
});
}
@@ -145,14 +142,10 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
.getCatalystInstance()
.removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(null);
final FpsDebugFrameCallback fpsDebugFrameCallback = this;
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mChoreographer = ChoreographerCompat.getInstance();
mChoreographer.removeFrameCallback(fpsDebugFrameCallback);
}
() -> {
mChoreographer = Choreographer.getInstance();
mChoreographer.removeFrameCallback(this);
});
}
@@ -7,15 +7,15 @@
package com.facebook.react.uimanager;
import android.view.Choreographer;
import com.facebook.react.bridge.JSExceptionHandler;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.core.ChoreographerCompat;
/**
* Abstract base for a Choreographer FrameCallback that should have any RuntimeExceptions it throws
* handled by the {@link JSExceptionHandler} registered if the app is in dev mode.
*/
public abstract class GuardedFrameCallback extends ChoreographerCompat.FrameCallback {
public abstract class GuardedFrameCallback implements Choreographer.FrameCallback {
private final ReactContext mReactContext;
@@ -8,12 +8,12 @@
package com.facebook.react.uimanager.events;
import android.util.LongSparseArray;
import android.view.Choreographer;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.systrace.Systrace;
@@ -272,7 +272,7 @@ public class EventDispatcherImpl implements EventDispatcher, LifecycleEventListe
mReactEventEmitter.unregister(uiManagerType);
}
private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback {
private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallback {
private volatile boolean mIsPosted = false;
private boolean mShouldStop = false;
@@ -7,10 +7,10 @@
package com.facebook.react.uimanager.events;
import android.view.Choreographer;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.systrace.Systrace;
@@ -125,7 +125,7 @@ public class FabricEventDispatcher implements EventDispatcher, LifecycleEventLis
mReactEventEmitter.unregister(uiManagerType);
}
private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback {
private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallback {
private volatile boolean mIsPosted = false;
private boolean mShouldStop = false;
@@ -7,6 +7,7 @@
package com.facebook.react.modules.timing
import android.view.Choreographer.FrameCallback
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.CatalystInstance
import com.facebook.react.bridge.JavaOnlyArray
@@ -14,7 +15,6 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableArray
import com.facebook.react.common.SystemClock
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.modules.core.ChoreographerCompat.FrameCallback
import com.facebook.react.modules.core.JSTimers
import com.facebook.react.modules.core.ReactChoreographer
import com.facebook.react.modules.core.ReactChoreographer.CallbackType
@@ -15,6 +15,7 @@ import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import android.graphics.Color;
import android.view.Choreographer;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -25,7 +26,6 @@ import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.views.text.ReactRawTextManager;
import com.facebook.react.views.text.ReactRawTextShadowNode;
@@ -50,7 +50,7 @@ public class UIManagerModuleTest {
private ReactApplicationContext mReactContext;
private CatalystInstance mCatalystInstanceMock;
private ArrayList<ChoreographerCompat.FrameCallback> mPendingFrameCallbacks;
private ArrayList<Choreographer.FrameCallback> mPendingFrameCallbacks;
private MockedStatic<Arguments> arguments;
private MockedStatic<ReactChoreographer> reactCoreographer;
@@ -71,13 +71,12 @@ public class UIManagerModuleTest {
doAnswer(
invocation -> {
mPendingFrameCallbacks.add(
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
(Choreographer.FrameCallback) invocation.getArguments()[1]);
return null;
})
.when(choreographerMock)
.postFrameCallback(
any(ReactChoreographer.CallbackType.class),
any(ChoreographerCompat.FrameCallback.class));
any(ReactChoreographer.CallbackType.class), any(Choreographer.FrameCallback.class));
mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
mReactContext = new ReactApplicationContext(RuntimeEnvironment.getApplication());
@@ -640,10 +639,9 @@ public class UIManagerModuleTest {
}
private void executePendingFrameCallbacks() {
ArrayList<ChoreographerCompat.FrameCallback> callbacks =
new ArrayList<>(mPendingFrameCallbacks);
ArrayList<Choreographer.FrameCallback> callbacks = new ArrayList<>(mPendingFrameCallbacks);
mPendingFrameCallbacks.clear();
for (ChoreographerCompat.FrameCallback frameCallback : callbacks) {
for (Choreographer.FrameCallback frameCallback : callbacks) {
frameCallback.doFrame(0);
}
}
@@ -24,6 +24,7 @@ import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.UnderlineSpan;
import android.view.Choreographer;
import android.widget.TextView;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.Arguments;
@@ -31,7 +32,6 @@ import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
@@ -57,7 +57,7 @@ public class ReactTextTest {
private MockedStatic<Arguments> arguments;
private MockedStatic<ReactChoreographer> reactCoreographer;
private ArrayList<ChoreographerCompat.FrameCallback> mPendingFrameCallbacks;
private ArrayList<Choreographer.FrameCallback> mPendingFrameCallbacks;
@Before
public void setUp() {
@@ -74,14 +74,13 @@ public class ReactTextTest {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mPendingFrameCallbacks.add(
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
(Choreographer.FrameCallback) invocation.getArguments()[1]);
return null;
}
})
.when(uiDriverMock)
.postFrameCallback(
any(ReactChoreographer.CallbackType.class),
any(ChoreographerCompat.FrameCallback.class));
any(ReactChoreographer.CallbackType.class), any(Choreographer.FrameCallback.class));
}
@Test
@@ -485,10 +484,9 @@ public class ReactTextTest {
}
private void executePendingFrameCallbacks() {
ArrayList<ChoreographerCompat.FrameCallback> callbacks =
new ArrayList<>(mPendingFrameCallbacks);
ArrayList<Choreographer.FrameCallback> callbacks = new ArrayList<>(mPendingFrameCallbacks);
mPendingFrameCallbacks.clear();
for (ChoreographerCompat.FrameCallback frameCallback : callbacks) {
for (Choreographer.FrameCallback frameCallback : callbacks) {
frameCallback.doFrame(0);
}
}
@@ -13,6 +13,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import android.view.Choreographer;
import android.widget.EditText;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.Arguments;
@@ -20,7 +21,6 @@ import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
@@ -41,7 +41,7 @@ import org.robolectric.RuntimeEnvironment;
@Ignore // TODO T110934492
public class TextInputTest {
private ArrayList<ChoreographerCompat.FrameCallback> mPendingChoreographerCallbacks;
private ArrayList<Choreographer.FrameCallback> mPendingChoreographerCallbacks;
private MockedStatic<Arguments> arguments;
private MockedStatic<ReactChoreographer> reactCoreographer;
@@ -61,13 +61,12 @@ public class TextInputTest {
doAnswer(
invocation -> {
mPendingChoreographerCallbacks.add(
(ChoreographerCompat.FrameCallback) invocation.getArguments()[1]);
(Choreographer.FrameCallback) invocation.getArguments()[1]);
return null;
})
.when(choreographerMock)
.postFrameCallback(
any(ReactChoreographer.CallbackType.class),
any(ChoreographerCompat.FrameCallback.class));
any(ReactChoreographer.CallbackType.class), any(Choreographer.FrameCallback.class));
}
@Test
@@ -141,10 +140,10 @@ public class TextInputTest {
}
private void executePendingChoreographerCallbacks() {
ArrayList<ChoreographerCompat.FrameCallback> callbacks =
ArrayList<Choreographer.FrameCallback> callbacks =
new ArrayList<>(mPendingChoreographerCallbacks);
mPendingChoreographerCallbacks.clear();
for (ChoreographerCompat.FrameCallback frameCallback : callbacks) {
for (Choreographer.FrameCallback frameCallback : callbacks) {
frameCallback.doFrame(0);
}
}