From 248c324ccae5bd40695dacf42c1048163fcc4f32 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 3 Oct 2023 08:00:16 -0700 Subject: [PATCH] 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 --- .../idledetection/ReactIdleDetectionUtil.java | 37 +++--- .../react/fabric/GuardedFrameCallback.java | 4 +- .../modules/core/ChoreographerCompat.java | 101 +-------------- .../react/modules/core/JavaTimerManager.java | 5 +- .../modules/core/ReactChoreographer.java | 120 ++++++++---------- .../DidJSUpdateUiDuringFrameDetector.java | 6 +- .../modules/debug/FpsDebugFrameCallback.java | 27 ++-- .../react/uimanager/GuardedFrameCallback.java | 4 +- .../uimanager/events/EventDispatcherImpl.java | 4 +- .../events/FabricEventDispatcher.java | 4 +- .../react/modules/timing/TimingModuleTest.kt | 2 +- .../react/uimanager/UIManagerModuleTest.java | 14 +- .../react/views/text/ReactTextTest.java | 14 +- .../react/views/textinput/TextInputTest.java | 13 +- 14 files changed, 117 insertions(+), 238 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/testing/idledetection/ReactIdleDetectionUtil.java b/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/testing/idledetection/ReactIdleDetectionUtil.java index a2e20984ec0ff6..3432d76c3bd846 100644 --- a/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/testing/idledetection/ReactIdleDetectionUtil.java +++ b/packages/react-native/ReactAndroid/src/androidTest/java/com/facebook/react/testing/idledetection/ReactIdleDetectionUtil.java @@ -9,10 +9,11 @@ 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 @@ private static void waitForChoreographer(long timeToWait) { 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)) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java index dcee5e2ebe8f91..8e4bdfaa60e38a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java @@ -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; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ChoreographerCompat.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ChoreographerCompat.java index 75346c42765719..f9f4f00453c0de 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ChoreographerCompat.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ChoreographerCompat.java @@ -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 {} } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java index f90205da5e131e..5f5e1abb8f64d3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java @@ -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 @@ private Timer(int callbackID, long initialTargetTime, int duration, boolean repe } } - 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 void doFrame(long frameTimeNanos) { } } - private class IdleFrameCallback extends ChoreographerCompat.FrameCallback { + private class IdleFrameCallback implements Choreographer.FrameCallback { @Override public void doFrame(long frameTimeNanos) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java index 84cd53006f6243..2abb9bf37f78d8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/ReactChoreographer.java @@ -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 @@ /** * 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 static ReactChoreographer getInstance() { } // 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(); - - @GuardedBy("mCallbackQueuesLock") - private final ArrayDeque[] mCallbackQueues; + private @Nullable volatile Choreographer mChoreographer; + + private final ArrayDeque[] 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 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 void run() { /** * 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 void removeFrameCallback( /** * 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 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(); - } - } - } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java index a7f1e77093df64..bb736e2903422c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DidJSUpdateUiDuringFrameDetector.java @@ -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 @@ * 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 synchronized void onViewHierarchyUpdateFinished() { } /** - * Designed to be called from a {@link ChoreographerCompat.FrameCallback#doFrame} call. + * Designed to be called from a {@link Choreographer.FrameCallback#doFrame} call. * *

There are two 'success' cases that will cause {@link #getDidJSHitFrameAndCleanup} to return * true for a given frame: diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java index 20f2bc3a5a103c..db33014aea0e6b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java @@ -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 @@ * 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 FpsInfo( 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 void doFrame(long l) { mTimeToFps.put(System.currentTimeMillis(), info); } mExpectedNumFramesPrev = expectedNumFrames; + if (mChoreographer != null) { mChoreographer.postFrameCallback(this); } @@ -123,14 +124,10 @@ public void start() { .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 void stop() { .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); }); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java index 5cee3f36a32fd5..5f8115c0faa4f8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java @@ -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; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java index 8b00f7766e1275..320b7df3a9b1df 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java @@ -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 void unregisterEventEmitter(@UIManagerType int uiManagerType) { mReactEventEmitter.unregister(uiManagerType); } - private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback { + private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallback { private volatile boolean mIsPosted = false; private boolean mShouldStop = false; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/FabricEventDispatcher.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/FabricEventDispatcher.java index 4c3387b3e0382d..953649288c239a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/FabricEventDispatcher.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/FabricEventDispatcher.java @@ -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 void unregisterEventEmitter(@UIManagerType int uiManagerType) { mReactEventEmitter.unregister(uiManagerType); } - private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback { + private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallback { private volatile boolean mIsPosted = false; private boolean mShouldStop = false; diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/timing/TimingModuleTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/timing/TimingModuleTest.kt index d18b246abb289c..116f1c122872eb 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/timing/TimingModuleTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/timing/TimingModuleTest.kt @@ -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 diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java index 9c30020c61d384..6daa049a499bbc 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java @@ -15,6 +15,7 @@ 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.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 mPendingFrameCallbacks; + private ArrayList mPendingFrameCallbacks; private MockedStatic arguments; private MockedStatic reactCoreographer; @@ -71,13 +71,12 @@ public void setUp() { 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 TestMoveDeleteHierarchy(ReactRootView nativeRootView, int rootViewTag) { } private void executePendingFrameCallbacks() { - ArrayList callbacks = - new ArrayList<>(mPendingFrameCallbacks); + ArrayList callbacks = new ArrayList<>(mPendingFrameCallbacks); mPendingFrameCallbacks.clear(); - for (ChoreographerCompat.FrameCallback frameCallback : callbacks) { + for (Choreographer.FrameCallback frameCallback : callbacks) { frameCallback.doFrame(0); } } diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java index e909a2ae2bc36e..577a2dc6c9096d 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/ReactTextTest.java @@ -24,6 +24,7 @@ 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.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; private MockedStatic reactCoreographer; - private ArrayList mPendingFrameCallbacks; + private ArrayList mPendingFrameCallbacks; @Before public void setUp() { @@ -74,14 +74,13 @@ public void setUp() { @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 @@ private ReactRootView createText( } private void executePendingFrameCallbacks() { - ArrayList callbacks = - new ArrayList<>(mPendingFrameCallbacks); + ArrayList callbacks = new ArrayList<>(mPendingFrameCallbacks); mPendingFrameCallbacks.clear(); - for (ChoreographerCompat.FrameCallback frameCallback : callbacks) { + for (Choreographer.FrameCallback frameCallback : callbacks) { frameCallback.doFrame(0); } } diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java index 4f2be905e22508..19dac17bcdc5ed 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/textinput/TextInputTest.java @@ -13,6 +13,7 @@ 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.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 @@ @Ignore // TODO T110934492 public class TextInputTest { - private ArrayList mPendingChoreographerCallbacks; + private ArrayList mPendingChoreographerCallbacks; private MockedStatic arguments; private MockedStatic reactCoreographer; @@ -61,13 +61,12 @@ public void setUp() { 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 void testPropsUpdate() { } private void executePendingChoreographerCallbacks() { - ArrayList callbacks = + ArrayList callbacks = new ArrayList<>(mPendingChoreographerCallbacks); mPendingChoreographerCallbacks.clear(); - for (ChoreographerCompat.FrameCallback frameCallback : callbacks) { + for (Choreographer.FrameCallback frameCallback : callbacks) { frameCallback.doFrame(0); } }