[General] Align pointerType across native and JS - #4403
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change adds a key pointer type to Android and Apple declarations. It also updates ChangesPointer type contract alignment
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
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
KEYentry to native pointer-type enums/constants (Android + Apple) soOTHERshifts to value4, matching JS. - Narrows
ButtonEvent.pointerTypefromnumbertoPointerTypein 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)
fddd5ec to
1728dd8
Compare
Description
The JS
PointerTypeenum isTOUCH, STYLUS, MOUSE, KEY, OTHER, but thenative constants stopped at
OTHER = 3— the value JS reads asKEY.Native pointer types travel to JS as plain ints with no translation layer
(
gestureHandlerCommon.tstypes them asPointerType), so every native"other pointer" surfaced as
PointerType.KEY, andPointerType.OTHERwasunreachable from native. It is reachable on Android through
TOOL_TYPE_ERASER/TOOL_TYPE_UNKNOWN, and on Apple through tvOSfocus-driven hover and any touch that is neither direct, pencil, nor
indirect pointer.
Declares
KEYon both platforms soOTHERlands on 4. Native never emitsKEY— it is produced only by the webKeyboardEventManager.With the values consistent,
ButtonEvent.pointerTypeis narrowed fromnumbertoPointerType. It only mirrored the codegen spec'sInt32; thespec keeps its own self-contained copy, so codegen is unaffected. Numeric
enums and
numberare mutually assignable, so this breaks no consumer —which is also why the
buttonEventTestdrift guard still passes. That guardcan no longer tell a deliberate refinement of this field from real spec
drift, but it still catches added, removed and retyped fields.
Test plan
:react-native-gesture-handler:compileDebugKotlinand:app:assembleDebuginapps/basic-example/androidboth succeedTouch0 …Key3,OtherPointer4); noswitchover the enum exists, so no-Wswitchfalloutyarn ts-checkclean (both passes),yarn test115/115,yarn lint:js0 errors
pod installfails on this machine forreasons unrelated to the change (rvm
libruby.2.7.dylibmismatch)