mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 22:38:37 +08:00
Fix dev menu on top of modals
Summary: The dialog intercepts all key events, we need to redirect some of them to the activity so that it can display the dev menu. Reviewed By: foghina Differential Revision: D3894503 fbshipit-source-id: fb62346a4da783f28a73c5a9e20566a451177629
This commit is contained in:
committed by
Facebook Github Bot 9
parent
f1ce6426fe
commit
3318483b31
@@ -13,6 +13,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -211,18 +212,25 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||
new DialogInterface.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
// We need to stop the BACK button from closing the dialog by default so we capture that
|
||||
// event and instead inform JS so that it can make the decision as to whether or not to
|
||||
// allow the back button to close the dialog. If it chooses to, it can just set visible
|
||||
// to false on the Modal and the Modal will go away
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
// We need to stop the BACK button from closing the dialog by default so we capture that
|
||||
// event and instead inform JS so that it can make the decision as to whether or not to
|
||||
// allow the back button to close the dialog. If it chooses to, it can just set visible
|
||||
// to false on the Modal and the Modal will go away
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Assertions.assertNotNull(
|
||||
mOnRequestCloseListener,
|
||||
"setOnRequestCloseListener must be called by the manager");
|
||||
mOnRequestCloseListener,
|
||||
"setOnRequestCloseListener must be called by the manager");
|
||||
mOnRequestCloseListener.onRequestClose(dialog);
|
||||
return true;
|
||||
} else {
|
||||
// We redirect the rest of the key events to the current activity, since the activity
|
||||
// expects to receive those events and react to them, ie. in the case of the dev menu
|
||||
Activity currentActivity = ((ReactContext) getContext()).getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
return currentActivity.onKeyUp(keyCode, event);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user