Update Pressable props - #4421
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 (7)
📝 WalkthroughSummary by CodeRabbit
WalkthroughPressable test-only props now forward hover callbacks across default and v3 implementations. Button prop types include hover compatibility fields. Gesture relation props accept single gestures or arrays. Tests cover default and relation-based engines. ChangesPressable testing compatibility
Sequence Diagram(s)sequenceDiagram
participant TestingLibrary
participant StatefulPressable
participant NativeButton
TestingLibrary->>StatefulPressable: Render press and hover handlers
StatefulPressable->>NativeButton: Forward testOnly_* callbacks
NativeButton->>TestingLibrary: Expose rendered callbacks
Possibly related issues
Possibly related PRs
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change enables hover-event testing across Pressable implementations and aligns relation prop types with supported array inputs without introducing an actionable merge-blocking risk; it is merge-ready after normal checks and review. 🚥 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
This PR improves React Native Testing Library (RNTL) compatibility for Pressable by forwarding hover handlers via testOnly_* props (guarded to test env only), and aligns the Pressable relation prop TypeScript types with the documented/runtime-supported behavior of accepting either a gesture or an array of gestures.
Changes:
- Forward
onHoverIn/onHoverOutastestOnly_onHoverIn/testOnly_onHoverOutfrom allPressableengines (LegacyPressable,StatefulPressable,PressableWithTouchable) underisTestEnv(). - Add
testOnly_onHoverIn/testOnly_onHoverOutto button prop types (ButtonProps,LegacyRawButtonProps). - Widen
Pressablerelation prop types (simultaneousWith/requireToFail/block) fromAnyGesturetoAnyGesture | AnyGesture[], matching JSDoc and runtime handling.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx | Forwards hover handlers as testOnly_* props in test env for the relation-enabled engine. |
| packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx | Forwards hover handlers as testOnly_* props in test env for the default v3 engine. |
| packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx | Widens relation prop types to accept a gesture or an array of gestures. |
| packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx | Forwards hover handlers as testOnly_* props in test env for the legacy Pressable. |
| packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx | Extends ButtonProps with testOnly_onHoverIn/testOnly_onHoverOut declarations. |
| packages/react-native-gesture-handler/src/components/GestureButtonsProps.ts | Extends legacy button prop types with testOnly_onHoverIn/testOnly_onHoverOut. |
| packages/react-native-gesture-handler/src/tests/mocks.test.tsx | Adds regression tests asserting hover testOnly_* props are exposed for both v3 engines. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
## Description Follow-up to #4416. None of the `Pressable` engines forwarded hover handlers as `testOnly_*` props, so `fireEvent(element, 'hoverIn')` from React Native Testing Library had no way to reach `onHoverIn`/`onHoverOut`. RNTL resolves `testOnly_on{EventName}` generically for any event, so exposing the props is all that's needed. This adds `testOnly_onHoverIn`/`testOnly_onHoverOut` to the button props and forwards them, guarded by `isTestEnv()`, from all three engines: legacy `Pressable`, `StatefulPressable` and `PressableWithTouchable`. Also widens the relation props (`simultaneousWith`/`requireToFail`/`block`) from `AnyGesture` to `AnyGesture | AnyGesture[]`. The JSDoc already promises a gesture object or an array of gesture objects and the runtime handles arrays in both directions (`relationUtils` flattens them into handler tags and pushes the symmetric relation onto each array element), only the prop type was narrowed. ## Test plan Added tests in `src/__tests__/mocks.test.tsx` asserting the hover props are wired on the button for both v3 engines — relation-free and routed to `StatefulPressable` via `simultaneousWith={[]}` (which the type widening makes legal). Both fail without the engine changes. In `packages/react-native-gesture-handler`: `yarn test`, `yarn ts-check` and `yarn lint:js` pass.
Description
Follow-up to #4416. None of the
Pressableengines forwarded hover handlers astestOnly_*props, sofireEvent(element, 'hoverIn')from React Native Testing Library had no way to reachonHoverIn/onHoverOut. RNTL resolvestestOnly_on{EventName}generically for any event, so exposing the props is all that's needed.This adds
testOnly_onHoverIn/testOnly_onHoverOutto the button props and forwards them, guarded byisTestEnv(), from all three engines: legacyPressable,StatefulPressableandPressableWithTouchable.Also widens the relation props (
simultaneousWith/requireToFail/block) fromAnyGesturetoAnyGesture | AnyGesture[]. The JSDoc already promises a gesture object or an array of gesture objects and the runtime handles arrays in both directions (relationUtilsflattens them into handler tags and pushes the symmetric relation onto each array element), only the prop type was narrowed.Test plan
Added tests in
src/__tests__/mocks.test.tsxasserting the hover props are wired on the button for both v3 engines — relation-free and routed toStatefulPressableviasimultaneousWith={[]}(which the type widening makes legal). Both fail without the engine changes.In
packages/react-native-gesture-handler:yarn test,yarn ts-checkandyarn lint:jspass.