Add HardwareBackPressEvent with native timestamp (#56295)#56295
Closed
rubennorte wants to merge 2 commits intofacebook:mainfrom
Closed
Add HardwareBackPressEvent with native timestamp (#56295)#56295rubennorte wants to merge 2 commits intofacebook:mainfrom
rubennorte wants to merge 2 commits intofacebook:mainfrom
Conversation
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D98941079. |
38f714a to
57c82c9
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
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`
Differential Revision: D98941079
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
Summary: Pull Request resolved: facebook#56295 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` Differential Revision: D98941079
57c82c9 to
723d2dd
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
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`
Differential Revision: D98941079
723d2dd to
37b5845
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
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`
Differential Revision: D98941079
37b5845 to
e3fe1da
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
Summary: Pull Request resolved: facebook#56295 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` Differential Revision: D98941079
e3fe1da to
c5cdc9c
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 1, 2026
Summary: Pull Request resolved: facebook#56295 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` Differential Revision: D98941079
c5cdc9c to
03f92c6
Compare
…EY (facebook#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
03f92c6 to
faf3975
Compare
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
|
This pull request has been merged in bf277cb. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Changelog: [Android][Added] - Pass event object to
BackHandlerhardwareBackPressevents to access timeStamp from native event.BackHandler on Android emits the
hardwareBackPressevent with anullpayload — 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:
SystemClock.uptimeMillis()astimestampin the nativeDeviceEventManagerModule.emitHardwareBackPressed()event payloadHardwareBackPressEventclass extending the DOMEventclass, which overrides the
timeStampgetter to return the nativetimestamp (falling back to
performance.now()if unavailable)TypeError("Illegal constructor")following the
PerformanceEntrypatternand type definitions (Flow, TypeScript) to create and pass the event
to handlers
mockPressBackHardwareBackPressEventandBackHandlerReviewed By: huntie
Differential Revision: D98941079