mirror of
https://github.com/status-im/react-native.git
synced 2025-02-21 13:48:13 +00:00
Refactor the usages of ChoreographerCompat
Summary: Reducing the places where we directly access `ChoreographerCompat.getInstance()`. Since this is a singleton anyway, there was no need to pass this as an argument. In subsequent diffs, we will also ensure that `ChoreographerCompat.getInstance()` runs on the UI thread, so that the `Choreographer` it gets is based on the `Looper` of the main thread. Reviewed By: achen1 Differential Revision: D10136624 fbshipit-source-id: ad18f7b61eb8b05094aff310f2eb90eb225427dc
This commit is contained in:
parent
8b487d4d5a
commit
a5f3571770
@ -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);
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ public class AnimationsDebugModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
mFrameCallback = new FpsDebugFrameCallback(
|
||||
ChoreographerCompat.getInstance(),
|
||||
getReactApplicationContext());
|
||||
mFrameCallback.startAndRecordFpsAtEachFrame();
|
||||
}
|
||||
|
@ -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<Long, FpsInfo> 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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user