-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix HitSlop type in config.
#3946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the typing of HitSlop in the v3 gesture config so that SharedValue can be used with HitSlop (e.g. useSharedValue(10)) without type errors and tightens the typing around config value unwrapping.
Changes:
- Refactors
SharedValueOrT/WithSharedValueto use distributive conditional types and aPparameter to selectively prevent union splitting, then removesHitSlopfrom the non-splittable set, allowingSharedValue<number>etc. to be assignable whereHitSlopis expected. - Narrows
maybeUnpackValue’s input type usingSharedValueOrT<T, boolean> | undefinedand updates call sites to specify the expected value type (e.g.<number>,<boolean>), improving type inference and safety when unwrapping config values. - Exposes the
ActiveCursortype from the package root index for consumers using the new v3 gesture config APIs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/react-native-gesture-handler/src/v3/types/ReanimatedTypes.ts |
Introduces the new SharedValueOrT<T, P> implementation and wires it into WithSharedValue/WithSharedValueRecursive to support union splitting with an escape hatch via P. |
packages/react-native-gesture-handler/src/v3/types/ConfigTypes.ts |
Updates CommonGestureConfig’s WithSharedValue parameter to only treat ActiveCursor and MouseButton as non-splittable, so HitSlop now benefits from the new union-splitting behavior. |
packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts |
Refines maybeUnpackValue’s signature to use SharedValueOrT<T, boolean> and return T, ensuring correct handling of boolean config flags and shared values. |
packages/react-native-gesture-handler/src/v3/hooks/gestures/pan/usePanGesture.ts |
Adds explicit type parameters to maybeUnpackValue calls for pan offsets, ensuring numbers are correctly inferred when validating and transforming offset props. |
packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts |
Adjusts use of maybeUnpackValue for enabled in test utilities to specify <boolean>, aligning with the new generic signature. |
packages/react-native-gesture-handler/src/index.ts |
Re-exports the ActiveCursor type from gestureHandlerCommon, making it available to library consumers at the package root. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tjzel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complicated, but LGTM
Description
Though we allowed
HitSlopto beSharedValuein gesture config, we excluded it from being split. Therefore if someone did something like:this wouldn't work as
SharedValue<number>couldn't be assigned toSharedValue<HitSlop>.This PR changes behavior of
SharedValueOrT<T>type, so that it uses Distributive Conditional Types to split union into separate types and then applySharedValue.Test plan
yarn ts-checkandyarn lint-jsTested on the following code: