Skip to content

Commit 3318483

Browse files
andreicoman11Facebook Github Bot 9
authored andcommitted
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
1 parent f1ce642 commit 3318483

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.util.ArrayList;
1515

16+
import android.app.Activity;
1617
import android.app.Dialog;
1718
import android.content.Context;
1819
import android.content.DialogInterface;
@@ -211,18 +212,25 @@ protected void showOrUpdate() {
211212
new DialogInterface.OnKeyListener() {
212213
@Override
213214
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
214-
// We need to stop the BACK button from closing the dialog by default so we capture that
215-
// event and instead inform JS so that it can make the decision as to whether or not to
216-
// allow the back button to close the dialog. If it chooses to, it can just set visible
217-
// to false on the Modal and the Modal will go away
218-
if (keyCode == KeyEvent.KEYCODE_BACK) {
219-
if (event.getAction() == KeyEvent.ACTION_UP) {
215+
if (event.getAction() == KeyEvent.ACTION_UP) {
216+
// We need to stop the BACK button from closing the dialog by default so we capture that
217+
// event and instead inform JS so that it can make the decision as to whether or not to
218+
// allow the back button to close the dialog. If it chooses to, it can just set visible
219+
// to false on the Modal and the Modal will go away
220+
if (keyCode == KeyEvent.KEYCODE_BACK) {
220221
Assertions.assertNotNull(
221-
mOnRequestCloseListener,
222-
"setOnRequestCloseListener must be called by the manager");
222+
mOnRequestCloseListener,
223+
"setOnRequestCloseListener must be called by the manager");
223224
mOnRequestCloseListener.onRequestClose(dialog);
225+
return true;
226+
} else {
227+
// We redirect the rest of the key events to the current activity, since the activity
228+
// expects to receive those events and react to them, ie. in the case of the dev menu
229+
Activity currentActivity = ((ReactContext) getContext()).getCurrentActivity();
230+
if (currentActivity != null) {
231+
return currentActivity.onKeyUp(keyCode, event);
232+
}
224233
}
225-
return true;
226234
}
227235
return false;
228236
}

0 commit comments

Comments
 (0)