Skip to content

Include the native event timestamp in onHWKeyEvent on Android - #58607

Closed
bumjung wants to merge 1 commit into
react:mainfrom
bumjung:export-D120451212
Closed

bumjung wants to merge 1 commit into
react:mainfrom
bumjung:export-D120451212

Conversation

@bumjung

@bumjung bumjung commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary:
onHWKeyEvent tells JS which key was pressed but not when it was pressed, so a listener can only time a press from the moment the device event reaches the JavaScript thread. That delivery is asynchronous, so any latency measured from JS silently excludes the native-to-JS hop — and excludes more of it the busier the JS thread is, which is exactly when the interaction is slowest.

Add the originating KeyEvent.getEventTime() to the event payload. It is SystemClock.uptimeMillis(), the same CLOCK_MONOTONIC base that performance.now() reads in JS, so a listener can subtract the two directly with no clock conversion. The field is omitted for the focus and blur events, which have no originating hardware event.

Additive and behaviour-preserving: no existing payload key changes, and nothing in the framework reads the new one.

Changelog

Changelog: [Android][Added] - Add eventTime to the onHWKeyEvent device event payload

Reviewed By: rozele

Differential Revision: D120451212

Summary:
`onHWKeyEvent` tells JS which key was pressed but not when it was pressed, so a listener can only time a press from the moment the device event reaches the JavaScript thread. That delivery is asynchronous, so any latency measured from JS silently excludes the native-to-JS hop — and excludes more of it the busier the JS thread is, which is exactly when the interaction is slowest.

Add the originating `KeyEvent.getEventTime()` to the event payload. It is `SystemClock.uptimeMillis()`, the same `CLOCK_MONOTONIC` base that `performance.now()` reads in JS, so a listener can subtract the two directly with no clock conversion. The field is omitted for the focus and blur events, which have no originating hardware event.

Additive and behaviour-preserving: no existing payload key changes, and nothing in the framework reads the new one.

## Changelog

Changelog: [Android][Added] - Add `eventTime` to the `onHWKeyEvent` device event payload

Reviewed By: rozele

Differential Revision: D120451212
@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 Sep 19, 2026
@meta-codesync

meta-codesync Bot commented Sep 19, 2026

Copy link
Copy Markdown

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

@meta-codesync meta-codesync Bot closed this in 15bb7e2 Sep 19, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Sep 19, 2026
@meta-codesync

meta-codesync Bot commented Sep 19, 2026

Copy link
Copy Markdown

This pull request has been merged in 15bb7e2.

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. 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.

1 participant