Skip to content

[Android] Escape key dismisses <Modal> natively without calling onRequestClose #60508

Backlog

Description

@ykdhan

Description

On Android 15 (API 35) and later, pressing the Escape key while a <Modal> is shown closes the Modal's dialog natively. onRequestClose is never called, so JS still thinks the Modal is visible (visible={true}) while nothing is on screen.

React Native is meant to leave that decision to JS. In ReactModalHostView, the dialog's OnKeyListener catches the BACK and ESCAPE key up and calls onRequestClose instead of closing the dialog. The comment there says it does this so that JS can decide whether to close the Modal.

Newer Android versions handle Escape on key down. AOSP change "Close dialogs and activity on Escape down" (bug 324221986, android.googlesource.com, mirror) moved this into Dialog.onKeyDown, which now calls cancel() on a cancelable dialog as soon as Escape is pressed. Before that change, Escape was handled on key up. In the SDK sources, Dialog.java for API 35 and 36 has the key-down handling, and API 34 still handles Escape on key up. The listener only looks at key ups, and the key down reaches Dialog.onKeyDown because no view consumes it. The dialog is therefore cancelled before the listener ever sees the Escape key up. React Native never calls setCancelable(false) on the dialog and registers no cancel or dismiss listener, so nothing tells JS that the Modal went away.

BACK is not affected: Dialog.onKeyDown only starts tracking BACK, and React Native handles the back press through its OnBackPressedCallback and the key-up listener.

While visible stays true after this, the screen under the Modal stops responding to taps. Touches still reach JS, but with a different target than the button that was tapped, and no onPress fires. Once visible is set to false (the reproducer used a dev menu item, because the buttons no longer respond) and then back to true, the Modal shows again.

Steps to reproduce

  1. Render a <Modal visible={visible} onRequestClose={() => { console.log('onRequestClose'); setVisible(false); }}> with some content, and open it.
  2. Press Escape on a hardware keyboard, or run adb shell input keyevent KEYCODE_ESCAPE.
  3. Expected: onRequestClose is called and the Modal stays on screen until JS sets visible to false. This is what happens on BACK, and on Escape on API 34.
  4. Actual: the Modal disappears immediately, onRequestClose is not logged, and visible is still true in JS.

Checked on Android emulators (sdk_gphone64_arm64, Google APIs images):

Emulator Escape
API 34 (Android 14) onRequestClose is called; visible becomes false (not affected)
API 35 (Android 15) Modal disappears, onRequestClose is not called, visible stays true
API 36 (Android 16) Modal disappears, onRequestClose is not called, visible stays true

I did not test on a physical device.

React Native Version

0.88.1 (reproducer). Also seen on main at d1204ac, in RNTester built from source on an API 36 emulator.

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 27.2.1
  CPU: (12) arm64 Apple M4 Pro
  Memory: 755.77 MB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.21.1
    path: /Users/ykdhan/.nvm/versions/node/v22.21.1/bin/node
  Yarn:
    version: 1.22.22
    path: /Users/ykdhan/.nvm/versions/node/v22.21.1/bin/yarn
  npm:
    version: 11.6.4
    path: /Users/ykdhan/.nvm/versions/node/v22.21.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.17.0
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 27.2
      - iOS 27.2
      - macOS 27.2
      - tvOS 27.2
      - visionOS 27.2
      - watchOS 27.2
  Android SDK:
    API Levels:
      - "33"
      - "34"
      - "35"
      - "36"
      - "37"
    Build Tools:
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 36.1.0
      - 37.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-36.1 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14344949
  Xcode:
    version: 27.2/27B52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.17
    path: /usr/bin/javac
  Ruby:
    version: 4.0.7
    path: /opt/homebrew/bin/ruby
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-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

No crash. With the reproducer on API 35/36, pressing Escape logs nothing; pressing Back logs "onRequestClose". On API 34, both log "onRequestClose".

MANDATORY Reproducer

https://github.com/ykdhan/rn-modal-escape-reproducer

Screenshots and Videos

API 36: Escape closes the Modal with no log, visible stays true, taps stop working
https://github.com/user-attachments/assets/ab8f98ce-59a9-4e96-89ac-7d55099d0556

API 34: Escape calls onRequestClose
https://github.com/user-attachments/assets/a95504ef-b178-4a09-80c5-f12f1e859bdc

Related: found while testing #60505 (key events inside Modal), which does not change this behavior.

Activity

  1. ykdhan commented on Dec 3, 2026

    @ykdhan
    Author

    I'd like to work on a fix. I'll open a PR with a test.

  2. GBS05577-Andrea commented on Dec 3, 2026

    @GBS05577-Andrea

    Thanks for bringing this issue to attention, I've opened a similar one several months ago here and some PRs followed, but no fixes until now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions