Skip to content

Commit 20931fe

Browse files
ahmdshrifmeta-codesync[bot]
authored andcommitted
Add missing pointer event types to the TypeScript PointerEvents interface (#57159)
Summary: The hand-written TypeScript types declare only **12 of the 20** pointer event handlers that `ViewProps` actually exposes (per the Flow source and the generated `react-native-strict-api` types). The `PointerEvents` interface in `Libraries/Types/CoreEventTypes.d.ts` is missing: - `onPointerOver` / `onPointerOverCapture` - `onPointerOut` / `onPointerOutCapture` - `onGotPointerCapture` / `onGotPointerCaptureCapture` - `onLostPointerCapture` / `onLostPointerCaptureCapture` These are part of the W3C Pointer Events API. They are declared in the Flow source — `Libraries/Components/View/ViewPropTypes.js` (all typed `(e: PointerEvent) => void`) — and in the generated `react-native-strict-api` types, but were missing from the hand-written TypeScript types, so TypeScript users get a type error using them on any built-in component: ``` Property 'onPointerOver' does not exist on type '... ViewProps'. Did you mean 'onPointerMove'? ``` This adds the 8 missing handlers to the `PointerEvents` interface (matching the existing 12) and a type test covering them. ## Changelog: [GENERAL] [FIXED] - Add missing pointer event handler types (`onPointerOver`, `onPointerOut`, `onGotPointerCapture`, `onLostPointerCapture`, and their `*Capture` variants) to the TypeScript types Pull Request resolved: #57159 Test Plan: `yarn test-typescript` passes. Verified before/after with `tsc -p packages/react-native/types/tsconfig.json`: - **Before** (props absent): the added type test fails with `Property 'onPointerOver' does not exist on type '... ViewProps'`. - **After**: passes — `<View onPointerOver={e => e.nativeEvent.pointerId} … />` type-checks for all 8 handlers, with the event correctly inferred as `PointerEvent`. Reviewed By: huntie Differential Revision: D108114655 Pulled By: fabriziocucci fbshipit-source-id: 08d364d2e156953027c0d951ab3d895a1eeab159
1 parent e4a5ed3 commit 20931fe

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/react-native/Libraries/Types/CoreEventTypes.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,12 @@ export interface PointerEvents {
265265
onPointerDownCapture?: ((event: PointerEvent) => void) | undefined;
266266
onPointerUp?: ((event: PointerEvent) => void) | undefined;
267267
onPointerUpCapture?: ((event: PointerEvent) => void) | undefined;
268+
onPointerOver?: ((event: PointerEvent) => void) | undefined;
269+
onPointerOverCapture?: ((event: PointerEvent) => void) | undefined;
270+
onPointerOut?: ((event: PointerEvent) => void) | undefined;
271+
onPointerOutCapture?: ((event: PointerEvent) => void) | undefined;
272+
onGotPointerCapture?: ((event: PointerEvent) => void) | undefined;
273+
onGotPointerCaptureCapture?: ((event: PointerEvent) => void) | undefined;
274+
onLostPointerCapture?: ((event: PointerEvent) => void) | undefined;
275+
onLostPointerCaptureCapture?: ((event: PointerEvent) => void) | undefined;
268276
}

packages/react-native/types/__typetests__/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,18 @@ const lists = StyleSheet.create({
338338

339339
const container = StyleSheet.compose(page.container, lists.listContainer);
340340
<View style={container} />;
341+
342+
// Pointer events (W3C): all variants should be accepted on View.
343+
<View
344+
onPointerOver={e => e.nativeEvent.pointerId}
345+
onPointerOverCapture={e => e.nativeEvent.pointerId}
346+
onPointerOut={e => e.nativeEvent.pointerId}
347+
onPointerOutCapture={e => e.nativeEvent.pointerId}
348+
onGotPointerCapture={e => e.nativeEvent.pointerId}
349+
onGotPointerCaptureCapture={e => e.nativeEvent.pointerId}
350+
onLostPointerCapture={e => e.nativeEvent.pointerId}
351+
onLostPointerCaptureCapture={e => e.nativeEvent.pointerId}
352+
/>;
341353
const text = StyleSheet.compose(page.text, lists.listItem) as TextStyle;
342354
<Text style={text} />;
343355

0 commit comments

Comments
 (0)