Android: with `enableKeyEvents` on, a focused View inside a `<Modal>` never receives `onKeyDown`
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 54/100
Research direction
Start with ReactModalHostView.kt, especially DialogRootViewGroup and the dialog's OnKeyListener; compare their key handling with ReactRootView.java and ReactSurfaceView.kt, where JSKeyDispatcher routes events and tracks focus. Reproduce with the linked app and enableKeyEvents enabled. Done when a focused View inside a Modal receives onKeyDown and onKeyUp, while Back or Escape still triggers onRequestClose.
Written by the indexing model from the issue text.
Description
Description
With ReactNativeFeatureFlags.enableKeyEvents() on, React Native Android sends a View's onKeyDown / onKeyUp from the React root's own key dispatch: ReactRootView.dispatchKeyEvent (L327) and ReactSurfaceView.dispatchJSKeyEvent (L200), each with a JSKeyDispatcher that tracks the focused child. A <Modal> renders into a dialog window whose root is ReactModalHostView.DialogRootViewGroup (L516), which has no key dispatch and no focus tracking, so a View inside a Modal receives no key event even while it holds focus. The dialog's OnKeyListener (L313) only turns Back or Escape into onRequestClose.
Steps to reproduce
The reproducer turns enableKeyEvents on in MainApplication.kt after loadReactNative, and renders a focusable View with onKeyDown that shows the last key it got, a button that opens a <Modal>, and the same View in the Modal.
- Clone the reproducer; in
ReproducerApp:yarn install, thencd android && ./gradlew assembleReleaseandadb install -r app/build/outputs/apk/release/app-release.apk. - Start the app.
adb shell input keyevent KEYCODE_TABfocuses the first View, andadb shell input keyevent KEYCODE_Amakes it showOutside the Modal, last key: a. - Tap Open the Modal, then
adb shell input keyevent KEYCODE_TAB, which focuses the View in the Modal, andadb shell input keyevent KEYCODE_A.
Expected: Inside the Modal, last key: a.
Seen: Inside the Modal, last key: none, with that View focused.
React Native Version
0.88.1
Affected Platforms
Runtime - Android
Output of npx @react-native-community/cli info
System:
OS: Windows 11 10.0.26300
CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor "
Memory: 201.56 GB / 255.67 GB
Binaries:
Node:
version: 26.12.1
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 1.22.22
path: C:\Users\yevhe.YEVHENII\AppData\Roaming\npm\yarn.CMD
npm:
version: 12.2.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels:
- "33"
- "35"
- "35"
- "35"
- "36"
- "37"
Build Tools:
- 35.0.0
- 36.0.0
- 36.1.0
- 37.0.0
System Images:
- android-26 | Google APIs Intel x86_64 Atom
- android-28 | Google APIs Intel x86_64 Atom
- android-29 | Google APIs Intel x86_64 Atom
- android-30 | Google APIs Intel x86_64 Atom
- android-31 | Google APIs Intel x86_64 Atom
- android-32 | Google APIs Intel x86_64 Atom
- android-33 | Google APIs Intel x86_64 Atom
- android-34 | Google APIs Intel x86_64 Atom
- android-35 | Google APIs Intel x86_64 Atom
- android-36.1 | Google Play Intel x86_64 Atom
- android-36.1 | Pre-Release 16 KB Page Size Google Play Intel x86_64 Atom
- android-37.0 | Google APIs Intel x86_64 Atom
Android NDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: AI-262.9437.185.2621.16467767
Visual Studio: Not Found
Languages:
Java:
version: 17.0.20.1
path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: 20.2.0
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.88.1
wanted: 0.88.1
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Stacktrace or Logs
No error is logged. The focused node (uiautomator dump) and the text of each View after each step, on a Galaxy S23 (Android 14):
{"device":"SM-S911B, Android 14"}
{"step":"started","focused":"none","shows":["Outside the Modal, last key: none"]}
{"step":"KEYCODE_TAB","focused":"outside-target","shows":["Outside the Modal, last key: none"]}
{"step":"KEYCODE_A","focused":"outside-target","shows":["Outside the Modal, last key: a"]}
{"step":"tapped Open the Modal","focused":"none","shows":["Inside the Modal, last key: none"]}
{"step":"KEYCODE_TAB in the Modal","focused":"inside-target","shows":["Inside the Modal, last key: none"]}
{"step":"KEYCODE_A in the Modal","focused":"inside-target","shows":["Inside the Modal, last key: none"]}
On main at c12d0b3e74, ReactModalHostView.kt differs from 0.88.1 only in dismissing a dialog of a destroyed Activity and in the navigation bar contrast of a transparent one; DialogRootViewGroup is the same.
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/rn-android-modal-key-events
Screenshots and Videos
No response
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.5k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 235
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react/react-native
-
Needs: Author Feedback Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
react/react-native#60059 · 1 comment ·
Maintainers usually reply within 2 days
-
Needs: Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
react/react-native#60000 ·
Maintainers usually reply within 2 days
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedPossibly taken @lazerg claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
react/react-native#59939 ·
Maintainers usually reply within 2 days
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryPossibly taken @alleneubank claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
react/react-native#59919 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
react/react-native#59722 ·
Maintainers usually reply within 2 days
All issues in react/react-native
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
petercorke/robotics-toolbox-python#943 · 1 comment ·
Maintainers usually reply within 1 day
-
area:build bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
NatronGitHub/openfx-arena#71 ·
Maintainers usually reply within 1 day
-
upstream-blocked
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ROCm/FastFlowLM#1057 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
NatronGitHub/openfx-gmic#45 ·
Maintainers usually reply within 1 day