diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.java index bcc5e3345..d190c0c40 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.java @@ -39,7 +39,7 @@ public class FpsView extends FrameLayout { super(reactContext); inflate(reactContext, R.layout.fps_view, this); mTextView = (TextView) findViewById(R.id.fps_text); - mFrameCallback = new FpsDebugFrameCallback(ChoreographerCompat.getInstance(), reactContext); + mFrameCallback = new FpsDebugFrameCallback(reactContext); mFPSMonitorRunnable = new FPSMonitorRunnable(); setCurrentFPS(0, 0, 0, 0); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/AnimationsDebugModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/AnimationsDebugModule.java index 69b0f70a1..df103404c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/AnimationsDebugModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/AnimationsDebugModule.java @@ -59,7 +59,6 @@ public class AnimationsDebugModule extends ReactContextBaseJavaModule { } mFrameCallback = new FpsDebugFrameCallback( - ChoreographerCompat.getInstance(), getReactApplicationContext()); mFrameCallback.startAndRecordFpsAtEachFrame(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java index f0de89626..eab166f2a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java @@ -7,6 +7,7 @@ package com.facebook.react.modules.debug; +import com.facebook.react.bridge.UiThreadUtil; import javax.annotation.Nullable; import java.util.Map; @@ -59,7 +60,7 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback { private static final double EXPECTED_FRAME_TIME = 16.9; - private final ChoreographerCompat mChoreographer; + private @Nullable ChoreographerCompat mChoreographer; private final ReactContext mReactContext; private final UIManagerModule mUIManagerModule; private final DidJSUpdateUiDuringFrameDetector mDidJSUpdateUiDuringFrameDetector; @@ -74,8 +75,7 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback { private boolean mIsRecordingFpsInfoAtEachFrame = false; private @Nullable TreeMap mTimeToFps; - public FpsDebugFrameCallback(ChoreographerCompat choreographer, ReactContext reactContext) { - mChoreographer = choreographer; + public FpsDebugFrameCallback(ReactContext reactContext) { mReactContext = reactContext; mUIManagerModule = reactContext.getNativeModule(UIManagerModule.class); mDidJSUpdateUiDuringFrameDetector = new DidJSUpdateUiDuringFrameDetector(); @@ -120,8 +120,9 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback { mTimeToFps.put(System.currentTimeMillis(), info); } mExpectedNumFramesPrev = expectedNumFrames; - - mChoreographer.postFrameCallback(this); + if (mChoreographer != null) { + mChoreographer.postFrameCallback(this); + } } public void start() { @@ -129,7 +130,14 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback { mReactContext.getCatalystInstance().addBridgeIdleDebugListener( mDidJSUpdateUiDuringFrameDetector); mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector); - mChoreographer.postFrameCallback(this); + final FpsDebugFrameCallback fpsDebugFrameCallback = this; + UiThreadUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + mChoreographer = ChoreographerCompat.getInstance(); + mChoreographer.postFrameCallback(fpsDebugFrameCallback); + } + }); } public void startAndRecordFpsAtEachFrame() {