Android: with `enableKeyEvents` on, a focused View inside a `<Modal>` never receives `onKeyDown`
Mantenedores costumam responder em até 2 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 54/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- C++
- Estrelas
- 127k
- Forks
- 25.5k
- Merge médio
- 3d 22h
- PRs com merge (30d)
- 235
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de react/react-native
-
Needs: Author Feedback Needs: Repro
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
react/react-native#60059 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Needs: Triage :mag:
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#60000 ·
Mantenedores costumam responder em até 2 dias
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedTalvez já em andamento @lazerg assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
react/react-native#59939 ·
Mantenedores costumam responder em até 2 dias
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryTalvez já em andamento @alleneubank assumiu há 6 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
react/react-native#59919 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#59722 ·
Mantenedores costumam responder em até 2 dias
Todas as issues de react/react-native
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
petercorke/robotics-toolbox-python#943 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
area:build bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
NatronGitHub/openfx-arena#71 ·
Mantenedores costumam responder em até 1 dia
-
upstream-blocked
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ROCm/FastFlowLM#1057 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
NatronGitHub/openfx-gmic#45 ·
Mantenedores costumam responder em até 1 dia