Skip to content

Commit 0e9d314

Browse files
alanjhughesmeta-codesync[bot]
authored andcommitted
Close the Android dev menu when the menu key is pressed again (#58668)
Summary: On Android, the menu key (`Cmd+M`) opens the dev menu, but a second press does not close it. On iOS, `Cmd+D` toggles the dev menu. This PR makes Android work the same way. ## Changelog: [ANDROID] [FIXED] - Pressing the menu key while the dev menu is open now closes it Pull Request resolved: #58668 Test Plan: RNTester on an emulator. Toggling works as expected Reviewed By: andrewdacenko Differential Revision: D121616477 Pulled By: shwanton fbshipit-source-id: 9d16a3349c5f9ddff5c7e46d5a590b9dbd525d3b
1 parent 585b28c commit 0e9d314

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.hardware.SensorManager
2323
import android.os.Build
2424
import android.util.Pair
2525
import android.view.Gravity
26+
import android.view.KeyEvent
2627
import android.view.View
2728
import android.view.ViewGroup
2829
import android.widget.ArrayAdapter
@@ -587,6 +588,15 @@ public abstract class DevSupportManagerBase(
587588
devOptionsDialog = null
588589
}
589590
.setOnCancelListener { devOptionsDialog = null }
591+
.setOnKeyListener { dialog: DialogInterface, keyCode: Int, event: KeyEvent ->
592+
if (keyCode != KeyEvent.KEYCODE_MENU) {
593+
return@setOnKeyListener false
594+
}
595+
if (event.action == KeyEvent.ACTION_UP) {
596+
dialog.cancel()
597+
}
598+
true
599+
}
590600
.create()
591601

592602
devOptionsDialog?.show()

0 commit comments

Comments
 (0)