Skip to content

Conversation

@Abbondanzo
Copy link
Contributor

Summary:
Adds support for onKeyDown/onKeyUp events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that ReactAndroidHWInputDeviceHelper uses to globally dispatch key and focus events: through the ReactRootView.

The event payload is based on a subset of web's W3C spec, intentionally omitting legacy charCode/keyCode fields. The payload contains:

The event payload on JS also omits the repeat and isComposing fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in #54295 called enableKeyEvents

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Differential Revision: D85022034

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 29, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 29, 2025

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D85022034.

Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Oct 29, 2025
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Differential Revision: D85022034
@react-native-bot
Copy link
Collaborator

react-native-bot commented Oct 29, 2025


Warnings
⚠️ ❗ JavaScript API change detected - This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. Please include a clear changelog message. This change will be subject to extra review.

This change was flagged as: BREAKING

Generated by 🚫 dangerJS against 719c18f

Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Oct 29, 2025
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Differential Revision: D85022034
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Oct 29, 2025
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Differential Revision: D85022034
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Nov 4, 2025
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Reviewed By: alanleedev

Differential Revision: D85022034
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Nov 18, 2025
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Reviewed By: alanleedev, sammy-SC

Differential Revision: D85022034
Summary:

Adds support for `onKeyDown`/`onKeyUp` events for Android views. Since views can only retain one key listener at a time, to avoid stomping over existing implementations, this change relies upon the same logic that `ReactAndroidHWInputDeviceHelper` uses to globally dispatch key and focus events: through the `ReactRootView`.

The event payload is based on [a subset of web's W3C spec](https://w3c.github.io/uievents/split/keyboard-events.html#events-keyboardevents), intentionally omitting legacy charCode/keyCode fields. The payload contains:
- boolean values for all four modifier keys,
- the key property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-key), and
- the code property [according to spec](https://w3c.github.io/uievents/split/keyboard-events.html#dom-keyboardeventinit-code), mapping Android keycode values to [this table](https://w3c.github.io/uievents-code/#code-value-tables)

The event payload on JS also omits the `repeat` and `isComposing` fields for the sake of compatibility with desktop implementations.

This change is gated behind a new feature flag introduced in facebook#54295 called `enableKeyEvents`

Changelog: [Android][Added] - Add onKeyDown/onKeyUp support to Android

Reviewed By: alanleedev, sammy-SC

Differential Revision: D85022034
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @Abbondanzo in 79b09ce

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 19, 2025
@meta-codesync
Copy link

meta-codesync bot commented Nov 19, 2025

This pull request has been merged in 79b09ce.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants