mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Update RedBoxDialog to separate content view and dialog
Summary: This diff separates the content view creation logic from existing `RedBoxDialog` logic. After the change, `RedBoxDialog` is no longer a subclass of `Dialog`, but behaves like a dialog with forwarding pattern to delegate dialog API to internal member. This will keep the APIs consistent with dependent components. The motivation of the change is to make the content view reusable. This is important in VR surface where we don't have activities and necessary implementations for Dialog to show. Changelog: [Android][Internal] Reviewed By: javache Differential Revision: D34016503 fbshipit-source-id: 261594bda9f6fb2d83764a1e5ec2e9e60d8d39a3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
99890bfacf
commit
97ce240a27
@@ -42,12 +42,15 @@ import okhttp3.RequestBody;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/** Dialog for displaying JS errors in an eye-catching form (red box). */
|
||||
/* package */ class RedBoxDialog extends Dialog implements AdapterView.OnItemClickListener {
|
||||
/* package */ class RedBoxDialog implements AdapterView.OnItemClickListener {
|
||||
|
||||
private final DevSupportManager mDevSupportManager;
|
||||
private final DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
|
||||
private final @Nullable RedBoxHandler mRedBoxHandler;
|
||||
private final View mContentView;
|
||||
private final Context mContext;
|
||||
|
||||
private @Nullable Dialog mDialog;
|
||||
private ListView mStackView;
|
||||
private Button mReloadJsButton;
|
||||
private Button mDismissButton;
|
||||
@@ -238,20 +241,17 @@ import org.json.JSONObject;
|
||||
|
||||
protected RedBoxDialog(
|
||||
Context context, DevSupportManager devSupportManager, @Nullable RedBoxHandler redBoxHandler) {
|
||||
super(context, R.style.Theme_Catalyst_RedBox);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
setContentView(R.layout.redbox_view);
|
||||
mContext = context;
|
||||
mContentView = (View) LayoutInflater.from(context).inflate(R.layout.redbox_view, null);
|
||||
|
||||
mDevSupportManager = devSupportManager;
|
||||
mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();
|
||||
mRedBoxHandler = redBoxHandler;
|
||||
|
||||
mStackView = (ListView) findViewById(R.id.rn_redbox_stack);
|
||||
mStackView = (ListView) mContentView.findViewById(R.id.rn_redbox_stack);
|
||||
mStackView.setOnItemClickListener(this);
|
||||
|
||||
mReloadJsButton = (Button) findViewById(R.id.rn_redbox_reload_button);
|
||||
mReloadJsButton = (Button) mContentView.findViewById(R.id.rn_redbox_reload_button);
|
||||
mReloadJsButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -259,7 +259,7 @@ import org.json.JSONObject;
|
||||
mDevSupportManager.handleReloadJS();
|
||||
}
|
||||
});
|
||||
mDismissButton = (Button) findViewById(R.id.rn_redbox_dismiss_button);
|
||||
mDismissButton = (Button) mContentView.findViewById(R.id.rn_redbox_dismiss_button);
|
||||
mDismissButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -269,12 +269,12 @@ import org.json.JSONObject;
|
||||
});
|
||||
|
||||
if (mRedBoxHandler != null && mRedBoxHandler.isReportEnabled()) {
|
||||
mLoadingIndicator = (ProgressBar) findViewById(R.id.rn_redbox_loading_indicator);
|
||||
mLineSeparator = (View) findViewById(R.id.rn_redbox_line_separator);
|
||||
mReportTextView = (TextView) findViewById(R.id.rn_redbox_report_label);
|
||||
mLoadingIndicator = (ProgressBar) mContentView.findViewById(R.id.rn_redbox_loading_indicator);
|
||||
mLineSeparator = (View) mContentView.findViewById(R.id.rn_redbox_line_separator);
|
||||
mReportTextView = (TextView) mContentView.findViewById(R.id.rn_redbox_report_label);
|
||||
mReportTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
mReportTextView.setHighlightColor(Color.TRANSPARENT);
|
||||
mReportButton = (Button) findViewById(R.id.rn_redbox_report_button);
|
||||
mReportButton = (Button) mContentView.findViewById(R.id.rn_redbox_report_button);
|
||||
mReportButton.setOnClickListener(mReportButtonOnClickListener);
|
||||
}
|
||||
}
|
||||
@@ -303,15 +303,39 @@ import org.json.JSONObject;
|
||||
AsyncTask.THREAD_POOL_EXECUTOR, (StackFrame) mStackView.getAdapter().getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||
mDevSupportManager.showDevOptionsDialog();
|
||||
return true;
|
||||
}
|
||||
if (mDoubleTapReloadRecognizer.didDoubleTapR(keyCode, getCurrentFocus())) {
|
||||
if (mDoubleTapReloadRecognizer.didDoubleTapR(keyCode, mDialog.getCurrentFocus())) {
|
||||
mDevSupportManager.handleReloadJS();
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
return mDialog.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
public View getContentView() {
|
||||
return mContentView;
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mDialog.isShowing();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (mDialog == null) {
|
||||
mDialog = new Dialog(mContext, R.style.Theme_Catalyst_RedBox);
|
||||
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
}
|
||||
mDialog.setContentView(mContentView);
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user