Skip to content

Add HardwareBackPressEvent with native timestamp (#56295) - #56295

Closed
rubennorte wants to merge 2 commits into
react:mainfrom
rubennorte:export-D98941079
Closed

Add HardwareBackPressEvent with native timestamp (#56295)#56295
rubennorte wants to merge 2 commits into
react:mainfrom
rubennorte:export-D98941079

Conversation

@rubennorte

@rubennorte rubennorte commented Mar 31, 2026

Copy link
Copy Markdown
Member

Summary:

Changelog: [Android][Added] - Pass event object to BackHandler hardwareBackPress events to access timeStamp from native event.

BackHandler on Android emits the hardwareBackPress event with a null
payload — no timestamp or event data. This means there is no way for
handlers to know when the user actually pressed the back button, which
prevents accurate performance tracing for back navigations.

This diff:

  • Sends SystemClock.uptimeMillis() as timestamp in the native
    DeviceEventManagerModule.emitHardwareBackPressed() event payload
  • Creates a new HardwareBackPressEvent class extending the DOM Event
    class, which overrides the timeStamp getter to return the native
    timestamp (falling back to performance.now() if unavailable)
  • Makes the public constructor throw TypeError("Illegal constructor")
    following the PerformanceEntry pattern
  • Updates all BackHandler platform files (Android, iOS, macOS, Windows)
    and type definitions (Flow, TypeScript) to create and pass the event
    to handlers
  • Updates the BackHandler mock to pass events in mockPressBack
  • Adds Fantom integration tests for both HardwareBackPressEvent and
    BackHandler

Reviewed By: huntie

Differential Revision: D98941079

@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 Mar 31, 2026
@meta-codesync

meta-codesync Bot commented Mar 31, 2026

Copy link
Copy Markdown

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

@meta-codesync meta-codesync Bot changed the title Add HardwareBackPressEvent with native timestamp Add HardwareBackPressEvent with native timestamp (#56295) Apr 1, 2026
@rubennorte
rubennorte force-pushed the export-D98941079 branch 6 times, most recently from c5cdc9c to 03f92c6 Compare April 1, 2026 10:52
…EY (#56304)

Summary:

Add support for specifying a custom `timeStamp` in the `Event` constructor options via a private symbol key (`EVENT_INIT_TIMESTAMP_KEY`) defined in `EventInternals`. This is for internal construction of events using a custom timestamp (instead of event object creation), for use cases like dispatching events from the host platform using the original timestamps.

- Added `EVENT_INIT_TIMESTAMP_KEY` symbol to `EventInternals`
- Added `setEventInitTimeStamp(eventInit, timeStamp)` helper function in `EventInternals` that validates the type and sets the symbol-keyed property on the event init object
- Updated the `Event` constructor to read the custom timestamp from options if present, falling back to `performance.now()`
- Added Fantom tests for custom timestamp and zero as a valid timestamp

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D99076591
Summary:

Changelog: [Android][Added] - Pass event object to `BackHandler` `hardwareBackPress` events to access timeStamp from native event.

BackHandler on Android emits the `hardwareBackPress` event with a `null`
payload — no timestamp or event data. This means there is no way for
handlers to know when the user actually pressed the back button, which
prevents accurate performance tracing for back navigations.

This diff:
- Sends `SystemClock.uptimeMillis()` as `timestamp` in the native
  `DeviceEventManagerModule.emitHardwareBackPressed()` event payload
- Creates a new `HardwareBackPressEvent` class extending the DOM `Event`
  class, which overrides the `timeStamp` getter to return the native
  timestamp (falling back to `performance.now()` if unavailable)
- Makes the public constructor throw `TypeError("Illegal constructor")`
  following the `PerformanceEntry` pattern
- Updates all BackHandler platform files (Android, iOS, macOS, Windows)
  and type definitions (Flow, TypeScript) to create and pass the event
  to handlers
- Updates the BackHandler mock to pass events in `mockPressBack`
- Adds Fantom integration tests for both `HardwareBackPressEvent` and
  `BackHandler`

Reviewed By: huntie

Differential Revision: D98941079
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

Warning

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

This change was flagged as: POTENTIALLY_BREAKING

@meta-codesync meta-codesync Bot closed this in bf277cb Apr 1, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label Apr 1, 2026
@meta-codesync

meta-codesync Bot commented Apr 1, 2026

Copy link
Copy Markdown

This pull request has been merged in bf277cb.

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.

1 participant