Android: with `enableKeyEvents` on, a focused View inside a `<Modal>` never receives `onKeyDown`
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 54/100
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- C++
- 星號
- 127k
- 分支
- 25.5k
- 平均合併
- 3 天 22 小時
- 30 天內合併 PR
- 235
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
react/react-native 的其他 Issue
-
Needs: Author Feedback Needs: Repro
難度 2/5 1-3 小時 新手友好度 82/100
react/react-native#60059 · 1 則留言 ·
維護者通常 2 天內回覆
-
Needs: Triage :mag:
難度 2/5 1-3 小時 新手友好度 70/100
react/react-native#60000 ·
維護者通常 2 天內回覆
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deleted可能已有人在做 @lazerg 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
react/react-native#59939 ·
維護者通常 2 天內回覆
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primary可能已有人在做 @alleneubank 於 6 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
react/react-native#59919 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
react/react-native#59722 ·
維護者通常 2 天內回覆
查看 react/react-native 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
petercorke/robotics-toolbox-python#943 · 1 則留言 ·
維護者通常 1 天內回覆
-
area:build bug
難度 1/5 1 小時以內 新手友好度 90/100
NatronGitHub/openfx-arena#71 ·
維護者通常 1 天內回覆
-
upstream-watcher: Netflix/vmaf cf677baaa039 is not ported可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉upstream-blocked
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
ROCm/FastFlowLM#1057 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
NatronGitHub/openfx-gmic#45 ·
維護者通常 1 天內回覆