Skip to content

[General] Align pointerType across native and JS - #4403

Merged
j-piasecki merged 1 commit into
mainfrom
jpiasecki/pointer-type-align
Aug 7, 2026
Merged

[General] Align pointerType across native and JS#4403
j-piasecki merged 1 commit into
mainfrom
jpiasecki/pointer-type-align

Conversation

@j-piasecki

Copy link
Copy Markdown
Member

Description

The JS PointerType enum is TOUCH, STYLUS, MOUSE, KEY, OTHER, but the
native constants stopped at OTHER = 3 — the value JS reads as KEY.
Native pointer types travel to JS as plain ints with no translation layer
(gestureHandlerCommon.ts types them as PointerType), so every native
"other pointer" surfaced as PointerType.KEY, and PointerType.OTHER was
unreachable from native. It is reachable on Android through
TOOL_TYPE_ERASER / TOOL_TYPE_UNKNOWN, and on Apple through tvOS
focus-driven hover and any touch that is neither direct, pencil, nor
indirect pointer.

Declares KEY on both platforms so OTHER lands on 4. Native never emits
KEY — it is produced only by the web KeyboardEventManager.

With the values consistent, ButtonEvent.pointerType is narrowed from
number to PointerType. It only mirrored the codegen spec's Int32; the
spec keeps its own self-contained copy, so codegen is unaffected. Numeric
enums and number are mutually assignable, so this breaks no consumer —
which is also why the buttonEventTest drift guard still passes. That guard
can no longer tell a deliberate refinement of this field from real spec
drift, but it still catches added, removed and retyped fields.

Test plan

  • Android: :react-native-gesture-handler:compileDebugKotlin and
    :app:assembleDebug in apps/basic-example/android both succeed
  • Apple: enum values pinned by a compiled assertion (Touch 0 … Key 3,
    OtherPointer 4); no switch over the enum exists, so no -Wswitch fallout
  • yarn ts-check clean (both passes), yarn test 115/115, yarn lint:js
    0 errors
  • The iOS app build was not run — pod install fails on this machine for
    reasons unrelated to the change (rvm libruby.2.7.dylib mismatch)

Copilot AI review requested due to automatic review settings August 7, 2026 09:53
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 742de098-c353-408c-91d6-546e5aaf1adf

📥 Commits

Reviewing files that changed from the base of the PR and between 7b35938 and fddd5ec.

📒 Files selected for processing (3)
  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt
  • packages/react-native-gesture-handler/apple/RNGestureHandlerPointerType.h
  • packages/react-native-gesture-handler/src/v3/types/EventTypes.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for identifying keyboard input as a pointer type across platforms.
    • Improved pointer event typing for button interactions.
  • Bug Fixes

    • Corrected pointer type values to distinguish keyboard input from other pointer sources.

Walkthrough

The change adds a key pointer type to Android and Apple declarations. It also updates ButtonEvent.pointerType to use the shared PointerType type.

Changes

Pointer type contract alignment

Layer / File(s) Summary
Add key pointer type declarations
packages/react-native-gesture-handler/android/.../GestureHandler.kt, packages/react-native-gesture-handler/apple/RNGestureHandlerPointerType.h, packages/react-native-gesture-handler/src/v3/types/EventTypes.ts
Android assigns a distinct value to key pointers and shifts the fallback value. Apple adds RNGestureHandlerKey. ButtonEvent.pointerType now uses PointerType.

Suggested reviewers: copilot, m-bert

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: aligning pointerType values and typing across native and JavaScript code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns pointerType numeric values between native (Android/Apple) and the JS PointerType enum so that native “other pointer” events no longer appear in JS as PointerType.KEY, and PointerType.OTHER becomes reachable from native inputs.

Changes:

  • Adds a KEY entry to native pointer-type enums/constants (Android + Apple) so OTHER shifts to value 4, matching JS.
  • Narrows ButtonEvent.pointerType from number to PointerType in v3 TypeScript event types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/react-native-gesture-handler/src/v3/types/EventTypes.ts Tightens ButtonEvent.pointerType typing to PointerType to reflect the aligned enum values.
packages/react-native-gesture-handler/apple/RNGestureHandlerPointerType.h Inserts RNGestureHandlerKey so RNGestureHandlerOtherPointer aligns to JS value 4.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt Inserts POINTER_TYPE_KEY = 3 and shifts POINTER_TYPE_OTHER to 4 to match JS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Description

The JS `PointerType` enum is `TOUCH, STYLUS, MOUSE, KEY, OTHER`, but the
native constants stopped at `OTHER = 3` — the value JS reads as `KEY`.
Native pointer types travel to JS as plain ints with no translation layer
(`gestureHandlerCommon.ts` types them as `PointerType`), so every native
"other pointer" surfaced as `PointerType.KEY`, and `PointerType.OTHER` was
unreachable from native. It is reachable on Android through
`TOOL_TYPE_ERASER` / `TOOL_TYPE_UNKNOWN`, and on Apple through tvOS
focus-driven hover and any touch that is neither direct, pencil, nor
indirect pointer.

Declares `KEY` on both platforms so `OTHER` lands on 4. Native never emits
`KEY` — it is produced only by the web `KeyboardEventManager`.

With the values consistent, `ButtonEvent.pointerType` is narrowed from
`number` to `PointerType`. It only mirrored the codegen spec's `Int32`; the
spec keeps its own self-contained copy, so codegen is unaffected. Numeric
enums and `number` are mutually assignable, so this breaks no consumer —
which is also why the `buttonEventTest` drift guard still passes. That guard
can no longer tell a deliberate refinement of this field from real spec
drift, but it still catches added, removed and retyped fields.

## Test plan

- Android: `:react-native-gesture-handler:compileDebugKotlin` and
  `:app:assembleDebug` in `apps/basic-example/android` both succeed
- Apple: enum values pinned by a compiled assertion (`Touch` 0 … `Key` 3,
  `OtherPointer` 4); no `switch` over the enum exists, so no `-Wswitch` fallout
- `yarn ts-check` clean (both passes), `yarn test` 115/115, `yarn lint:js`
  0 errors
- The iOS app build was not run — `pod install` fails on this machine for
  reasons unrelated to the change (rvm `libruby.2.7.dylib` mismatch)
@j-piasecki
j-piasecki force-pushed the jpiasecki/pointer-type-align branch from fddd5ec to 1728dd8 Compare August 7, 2026 12:45
@j-piasecki
j-piasecki merged commit 2b37b3c into main Aug 7, 2026
10 checks passed
@j-piasecki
j-piasecki deleted the jpiasecki/pointer-type-align branch August 7, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants