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 f4197d63b7a9a0..20f2bc3a5a103c 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 @@ -63,7 +63,6 @@ public FpsInfo( private final UIManagerModule mUIManagerModule; private final DidJSUpdateUiDuringFrameDetector mDidJSUpdateUiDuringFrameDetector; - private boolean mShouldStop = false; private long mFirstFrameTime = -1; private long mLastFrameTime = -1; private int mNumFrameCallbacks = 0; @@ -82,10 +81,6 @@ public FpsDebugFrameCallback(ReactContext reactContext) { @Override public void doFrame(long l) { - if (mShouldStop) { - return; - } - if (mFirstFrameTime == -1) { mFirstFrameTime = l; } @@ -124,7 +119,6 @@ public void doFrame(long l) { } public void start() { - mShouldStop = false; mReactContext .getCatalystInstance() .addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); @@ -147,11 +141,19 @@ public void startAndRecordFpsAtEachFrame() { } public void stop() { - mShouldStop = true; mReactContext .getCatalystInstance() .removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); mUIManagerModule.setViewHierarchyUpdateDebugListener(null); + final FpsDebugFrameCallback fpsDebugFrameCallback = this; + UiThreadUtil.runOnUiThread( + new Runnable() { + @Override + public void run() { + mChoreographer = ChoreographerCompat.getInstance(); + mChoreographer.removeFrameCallback(fpsDebugFrameCallback); + } + }); } public double getFPS() {