Skip to content

Conversation

Saadnajmi
Copy link
Collaborator

@Saadnajmi Saadnajmi commented Sep 19, 2025

Summary:

Implement onKeyDown, onKeyUp, keyDownEvents, and keyUpEvents on View for Fabric.

Note:

  • This requires a breaking change to the paper implementation of the events from DirectEvent --> BubblingEvent as the View configs are shared. The fact we treated keyboard events as direct is a holder from our legacy implementation involving validKeysDown and validKeysUp, so I'm happy to remove and align the two implementations.
  • We actually had a bug where both keyDownEvents and keyUpEvents were never passed into <View> 🤦, which we now fix in this PR. As such, I'll probably backport that fix to older stable branches.

Test Plan:

I added a new example to the keyboard events example page in RNTester, which looks quite good :)

Screenshot 2025-09-24 at 5 49 38 PM

@Saadnajmi Saadnajmi force-pushed the keyboard branch 3 times, most recently from 8c1ba9d to 6b76e90 Compare September 22, 2025 20:33
Nick Lefever and others added 10 commits September 22, 2025 17:42
Summary:
This diff adds the `validKeyDown` and `validKeyUp` props to the View component to provide a list of key event matchers used to filter out key event that have to be handled manually by the JS side.

These properties were added through the HostPlatformViewProps class to keep the macOS specific properties in a separate file from the iOS ViewProps.

Test Plan: Tested later in this stack.

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D53241733

Tasks: T157889406, T154618477
Summary:
This diff adds the event emitters that will be used by the keyboard handler of the View component.

The `KeyEvent` struct provides the same fields that were previously submitted by Paper. An equals operator between `KeyEvent` and `HandledKey` allows to check if a key event matches the criteria defined by the handled key description.

The event emitters were added using the HostPlatformEventEmitter so that the macOS specific changes would be kept separate from the iOS version.

Test Plan: Tested later in this stack.

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D53241730

Tasks: T157889406, T154618477
Summary:
This diff adds key down/up handling to the View component. The key events are checked against the provided list of key strokes that should be manually handled. If a match is found, the corresponding keyDown/Up event emitter is provided with the captured key even.

This will allow the View component to receive keyboard events and respond accordingly.

Test Plan: Tested later in this stack.

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D53241731

Tasks: T157889406, T154618477
Summary:
This diff fixes a crash happening when a key up/down event was processed by a non-focusable view with no "handled keys" configured on the view.

This would lead to an iteration over an optional vector that had no values set.

Test Plan:
* Run Zeratul with Fabric enabled
* Focus the search field
* Tab to toggle the focus until it reaches the message thread list
* Tab to the next focusable view

| Before | After |
|--|
| https://pxl.cl/4n91l |  https://pxl.cl/4n910  |
| Crash when tabbing out of thread list | No more crash |

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D53930899
@Saadnajmi Saadnajmi changed the title feat(fabric): Implement keyboard event handling on View feat(fabric)!: Implement keyboard event handling on View Sep 25, 2025
@Saadnajmi Saadnajmi marked this pull request as ready for review September 25, 2025 00:55
@Saadnajmi Saadnajmi requested a review from a team as a code owner September 25, 2025 00:55
Saadnajmi and others added 5 commits September 29, 2025 12:15
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
…w/RCTViewComponentView.mm

Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
@Saadnajmi Saadnajmi merged commit 69fe24f into microsoft:main Sep 30, 2025
21 checks passed
@Saadnajmi Saadnajmi deleted the keyboard branch September 30, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants