Permalink
Browse files

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
  • Loading branch information...
1 parent f1ce642 commit 3318483b313546a47d1519a52c84ed4e4d9bebd1 @andreicoman11 andreicoman11 committed with Facebook Github Bot 9 Sep 22, 2016
Showing with 17 additions and 9 deletions.
  1. +17 −9 ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java
@@ -13,6 +13,7 @@
import java.util.ArrayList;
+import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -211,18 +212,25 @@ protected void showOrUpdate() {
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;
}

0 comments on commit 3318483

Please sign in to comment.