dillon1000/react

Commit

[RN] Fix timeStamp property of SyntheticEvent in React Native (#35912)

## Summary

This fixes the semantics of the `timeStamp` property of events in React
Native.

Currently, most events just assign `Date.now()` (at the time of creating
the event object in JavaScript) as the `timeStamp` property. This is a
divergence with Web and most native platforms, that use a monotonic
timestamp for the value (on Web, the same timestamp provided by
`performance.now()`).

Additionally, many native events specify a timestamp in the event data
object as `timestamp` and gets ignored by the logic in JS as it only
looks at properties named `timeStamp` specifically (camel case).

This PR fixes both issues by:
1. Using `performance.now()` instead of `Date.now()` by default (if
available).
2. Checking for a `timestamp` property before falling back to the
default (apart from `timeStamp`).

## How did you test this change?

Added unit tests for verify the new behavior.
Browse files
Changed paths2 files
First-parent comparison
M packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js ModifiedM packages/react-native-renderer/src/legacy-events/SyntheticEvent.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…