|
13 | 13 |
|
14 | 14 | import java.util.ArrayList; |
15 | 15 |
|
| 16 | +import android.app.Activity; |
16 | 17 | import android.app.Dialog; |
17 | 18 | import android.content.Context; |
18 | 19 | import android.content.DialogInterface; |
@@ -211,18 +212,25 @@ protected void showOrUpdate() { |
211 | 212 | new DialogInterface.OnKeyListener() { |
212 | 213 | @Override |
213 | 214 | 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) { |
220 | 221 | Assertions.assertNotNull( |
221 | | - mOnRequestCloseListener, |
222 | | - "setOnRequestCloseListener must be called by the manager"); |
| 222 | + mOnRequestCloseListener, |
| 223 | + "setOnRequestCloseListener must be called by the manager"); |
223 | 224 | 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 | + } |
224 | 233 | } |
225 | | - return true; |
226 | 234 | } |
227 | 235 | return false; |
228 | 236 | } |
|
0 commit comments