Skip to content

Commit 4fcd997

Browse files
ayc1facebook-github-bot
authored andcommitted
Fix crash when reloading with Perf Monitor enabled
Reviewed By: mdvacca Differential Revision: D7678392 fbshipit-source-id: 5fcf3bda545896f48543a95d4885c6492fac961e
1 parent b92b38a commit 4fcd997

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DebugOverlayController.java

+25-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.facebook.common.logging.FLog;
2323
import com.facebook.react.bridge.ReactContext;
24+
import com.facebook.react.bridge.UiThreadUtil;
2425
import com.facebook.react.common.ReactConstants;
2526

2627
import javax.annotation.Nullable;
@@ -94,25 +95,30 @@ public DebugOverlayController(ReactContext reactContext) {
9495
mWindowManager = (WindowManager) reactContext.getSystemService(Context.WINDOW_SERVICE);
9596
}
9697

97-
public void setFpsDebugViewVisible(boolean fpsDebugViewVisible) {
98-
if (fpsDebugViewVisible && mFPSDebugViewContainer == null) {
99-
if (!permissionCheck(mReactContext)) {
100-
FLog.d(ReactConstants.TAG, "Wait for overlay permission to be set");
101-
return;
102-
}
103-
mFPSDebugViewContainer = new FpsView(mReactContext);
104-
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
105-
WindowManager.LayoutParams.MATCH_PARENT,
106-
WindowManager.LayoutParams.MATCH_PARENT,
107-
WindowOverlayCompat.TYPE_SYSTEM_OVERLAY,
108-
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
98+
public void setFpsDebugViewVisible(final boolean fpsDebugViewVisible) {
99+
UiThreadUtil.runOnUiThread(new Runnable() {
100+
@Override
101+
public void run() {
102+
if (fpsDebugViewVisible && mFPSDebugViewContainer == null) {
103+
if (!permissionCheck(mReactContext)) {
104+
FLog.d(ReactConstants.TAG, "Wait for overlay permission to be set");
105+
return;
106+
}
107+
mFPSDebugViewContainer = new FpsView(mReactContext);
108+
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
109+
WindowManager.LayoutParams.MATCH_PARENT,
110+
WindowManager.LayoutParams.MATCH_PARENT,
111+
WindowOverlayCompat.TYPE_SYSTEM_OVERLAY,
112+
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
109113
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
110-
PixelFormat.TRANSLUCENT);
111-
mWindowManager.addView(mFPSDebugViewContainer, params);
112-
} else if (!fpsDebugViewVisible && mFPSDebugViewContainer != null) {
113-
mFPSDebugViewContainer.removeAllViews();
114-
mWindowManager.removeView(mFPSDebugViewContainer);
115-
mFPSDebugViewContainer = null;
116-
}
114+
PixelFormat.TRANSLUCENT);
115+
mWindowManager.addView(mFPSDebugViewContainer, params);
116+
} else if (!fpsDebugViewVisible && mFPSDebugViewContainer != null) {
117+
mFPSDebugViewContainer.removeAllViews();
118+
mWindowManager.removeView(mFPSDebugViewContainer);
119+
mFPSDebugViewContainer = null;
120+
}
121+
}
122+
});
117123
}
118124
}

0 commit comments

Comments
 (0)