react-native-gesture-handler 3.2.0-nightly-20260811-cc704f09a → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/android/build.gradle +21 -6
  2. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +30 -66
  3. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +4 -2
  4. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt +1 -2
  5. package/apple/RNGestureHandler.mm +31 -23
  6. package/apple/RNGestureHandlerButtonComponentView.mm +10 -6
  7. package/lib/module/components/GestureHandlerButton.web.js +3 -2
  8. package/lib/module/components/GestureHandlerButton.web.js.map +1 -1
  9. package/lib/module/components/ReanimatedDrawerLayout.js +3 -0
  10. package/lib/module/components/ReanimatedDrawerLayout.js.map +1 -1
  11. package/lib/module/components/touchables/TouchableOpacity.js +1 -0
  12. package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
  13. package/lib/module/handlers/hitSlop.js +101 -0
  14. package/lib/module/handlers/hitSlop.js.map +1 -0
  15. package/lib/module/handlers/utils.js +3 -7
  16. package/lib/module/handlers/utils.js.map +1 -1
  17. package/lib/module/specs/RNGestureHandlerDetectorNativeComponent.ts +1 -1
  18. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.ts +1 -1
  19. package/lib/module/v3/components/Pressable.js +23 -312
  20. package/lib/module/v3/components/Pressable.js.map +1 -1
  21. package/lib/module/v3/components/PressableWithTouchable.js +259 -0
  22. package/lib/module/v3/components/PressableWithTouchable.js.map +1 -0
  23. package/lib/module/v3/components/StatefulPressable.js +338 -0
  24. package/lib/module/v3/components/StatefulPressable.js.map +1 -0
  25. package/lib/module/v3/components/pointerStyle.js +6 -0
  26. package/lib/module/v3/components/pointerStyle.js.map +1 -0
  27. package/lib/module/v3/components/pointerStyle.web.js +9 -0
  28. package/lib/module/v3/components/pointerStyle.web.js.map +1 -0
  29. package/lib/module/v3/hooks/utils/configUtils.js +3 -1
  30. package/lib/module/v3/hooks/utils/configUtils.js.map +1 -1
  31. package/lib/module/v3/hooks/utils/reanimatedUtils.js +14 -3
  32. package/lib/module/v3/hooks/utils/reanimatedUtils.js.map +1 -1
  33. package/lib/module/web/handlers/GestureHandler.js +21 -44
  34. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  35. package/lib/module/web/interfaces.js.map +1 -1
  36. package/lib/typescript/components/GestureComponents.web.d.ts +12 -4
  37. package/lib/typescript/components/GestureComponents.web.d.ts.map +1 -1
  38. package/lib/typescript/components/GestureHandlerButton.web.d.ts.map +1 -1
  39. package/lib/typescript/components/ReanimatedDrawerLayout.d.ts.map +1 -1
  40. package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -1
  41. package/lib/typescript/components/touchables/TouchableHighlight.d.ts.map +1 -1
  42. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +1 -1
  43. package/lib/typescript/handlers/hitSlop.d.ts +51 -0
  44. package/lib/typescript/handlers/hitSlop.d.ts.map +1 -0
  45. package/lib/typescript/handlers/utils.d.ts.map +1 -1
  46. package/lib/typescript/mocks/hostDetector.d.ts +5 -2
  47. package/lib/typescript/mocks/hostDetector.d.ts.map +1 -1
  48. package/lib/typescript/specs/RNGestureHandlerDetectorNativeComponent.d.ts +1 -1
  49. package/lib/typescript/specs/RNGestureHandlerDetectorNativeComponent.d.ts.map +1 -1
  50. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +1 -1
  51. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -1
  52. package/lib/typescript/v3/components/GestureComponents.web.d.ts +16 -8
  53. package/lib/typescript/v3/components/GestureComponents.web.d.ts.map +1 -1
  54. package/lib/typescript/v3/components/Pressable.d.ts +13 -0
  55. package/lib/typescript/v3/components/Pressable.d.ts.map +1 -1
  56. package/lib/typescript/v3/components/PressableWithTouchable.d.ts +5 -0
  57. package/lib/typescript/v3/components/PressableWithTouchable.d.ts.map +1 -0
  58. package/lib/typescript/v3/components/StatefulPressable.d.ts +5 -0
  59. package/lib/typescript/v3/components/StatefulPressable.d.ts.map +1 -0
  60. package/lib/typescript/v3/components/pointerStyle.d.ts +3 -0
  61. package/lib/typescript/v3/components/pointerStyle.d.ts.map +1 -0
  62. package/lib/typescript/v3/components/pointerStyle.web.d.ts +3 -0
  63. package/lib/typescript/v3/components/pointerStyle.web.d.ts.map +1 -0
  64. package/lib/typescript/v3/detectors/ReanimatedNativeDetector.d.ts +3 -1
  65. package/lib/typescript/v3/detectors/ReanimatedNativeDetector.d.ts.map +1 -1
  66. package/lib/typescript/v3/detectors/ReanimatedNativeDetector.web.d.ts +3 -1
  67. package/lib/typescript/v3/detectors/ReanimatedNativeDetector.web.d.ts.map +1 -1
  68. package/lib/typescript/v3/detectors/common.d.ts +2 -2
  69. package/lib/typescript/v3/detectors/common.d.ts.map +1 -1
  70. package/lib/typescript/v3/hooks/utils/configUtils.d.ts.map +1 -1
  71. package/lib/typescript/v3/hooks/utils/reanimatedUtils.d.ts.map +1 -1
  72. package/lib/typescript/v3/types/ConfigTypes.d.ts +2 -1
  73. package/lib/typescript/v3/types/ConfigTypes.d.ts.map +1 -1
  74. package/lib/typescript/v3/types/EventTypes.d.ts +3 -2
  75. package/lib/typescript/v3/types/EventTypes.d.ts.map +1 -1
  76. package/lib/typescript/web/handlers/GestureHandler.d.ts +0 -1
  77. package/lib/typescript/web/handlers/GestureHandler.d.ts.map +1 -1
  78. package/lib/typescript/web/interfaces.d.ts +3 -12
  79. package/lib/typescript/web/interfaces.d.ts.map +1 -1
  80. package/package.json +6 -6
  81. package/src/components/GestureHandlerButton.web.tsx +3 -2
  82. package/src/components/ReanimatedDrawerLayout.tsx +3 -0
  83. package/src/components/touchables/TouchableOpacity.tsx +1 -0
  84. package/src/handlers/hitSlop.ts +146 -0
  85. package/src/handlers/utils.ts +4 -2
  86. package/src/specs/RNGestureHandlerDetectorNativeComponent.ts +1 -1
  87. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +1 -1
  88. package/src/v3/components/Pressable.tsx +28 -448
  89. package/src/v3/components/PressableWithTouchable.tsx +326 -0
  90. package/src/v3/components/StatefulPressable.tsx +476 -0
  91. package/src/v3/components/pointerStyle.ts +5 -0
  92. package/src/v3/components/pointerStyle.web.ts +6 -0
  93. package/src/v3/hooks/utils/configUtils.ts +7 -1
  94. package/src/v3/hooks/utils/reanimatedUtils.ts +17 -8
  95. package/src/v3/types/ConfigTypes.ts +2 -1
  96. package/src/v3/types/EventTypes.ts +7 -3
  97. package/src/web/handlers/GestureHandler.ts +26 -77
  98. package/src/web/interfaces.ts +3 -13
@@ -7,6 +7,7 @@ import type {
7
7
  UserSelect,
8
8
  } from '../../handlers/gestureHandlerCommon';
9
9
  import { MouseButton } from '../../handlers/gestureHandlerCommon';
10
+ import type { NormalizedHitSlop } from '../../handlers/hitSlop';
10
11
  import { PointerType } from '../../PointerType';
11
12
  import { State } from '../../State';
12
13
  import { TouchEventType } from '../../TouchEventType';
@@ -21,7 +22,6 @@ import type {
21
22
  AdaptedEvent,
22
23
  Config,
23
24
  GestureHandlerNativeEvent,
24
- HitSlop,
25
25
  HostDetector,
26
26
  PointerData,
27
27
  PropsRef,
@@ -54,7 +54,7 @@ export default abstract class GestureHandler implements IGestureHandler {
54
54
  private _handlerTag!: number;
55
55
  private _testID?: string | undefined = undefined;
56
56
 
57
- private hitSlop?: HitSlop | undefined = undefined;
57
+ private hitSlop?: NormalizedHitSlop | undefined = undefined;
58
58
  private manualActivation: boolean = false;
59
59
  private mouseButton?: MouseButton | undefined = undefined;
60
60
  private needsPointerData: boolean = false;
@@ -795,7 +795,6 @@ export default abstract class GestureHandler implements IGestureHandler {
795
795
  // `undefined` means the property was not part of this update.
796
796
  if (config.hitSlop !== undefined) {
797
797
  this.hitSlop = config.hitSlop ?? undefined;
798
- this.validateHitSlops();
799
798
  }
800
799
 
801
800
  if (config.testID !== undefined) {
@@ -870,52 +869,6 @@ export default abstract class GestureHandler implements IGestureHandler {
870
869
  }
871
870
  }
872
871
 
873
- private validateHitSlops(): void {
874
- if (!this.hitSlop) {
875
- return;
876
- }
877
-
878
- if (
879
- this.hitSlop.left !== undefined &&
880
- this.hitSlop.right !== undefined &&
881
- this.hitSlop.width !== undefined
882
- ) {
883
- throw new Error(
884
- 'HitSlop Error: Cannot define left, right and width at the same time'
885
- );
886
- }
887
-
888
- if (
889
- this.hitSlop.width !== undefined &&
890
- this.hitSlop.left === undefined &&
891
- this.hitSlop.right === undefined
892
- ) {
893
- throw new Error(
894
- 'HitSlop Error: When width is defined, either left or right has to be defined'
895
- );
896
- }
897
-
898
- if (
899
- this.hitSlop.height !== undefined &&
900
- this.hitSlop.top !== undefined &&
901
- this.hitSlop.bottom !== undefined
902
- ) {
903
- throw new Error(
904
- 'HitSlop Error: Cannot define top, bottom and height at the same time'
905
- );
906
- }
907
-
908
- if (
909
- this.hitSlop.height !== undefined &&
910
- this.hitSlop.top === undefined &&
911
- this.hitSlop.bottom === undefined
912
- ) {
913
- throw new Error(
914
- 'HitSlop Error: When height is defined, either top or bottom has to be defined'
915
- );
916
- }
917
- }
918
-
919
872
  private checkHitSlop(): boolean {
920
873
  if (!this.hitSlop) {
921
874
  return true;
@@ -923,50 +876,46 @@ export default abstract class GestureHandler implements IGestureHandler {
923
876
 
924
877
  const { width, height } = this.delegate.measureView();
925
878
 
879
+ // A uniform hit slop stays a plain number on the wire, so expand it here.
880
+ const [slopLeft, slopTop, slopRight, slopBottom, slopWidth, slopHeight] =
881
+ typeof this.hitSlop === 'number'
882
+ ? [this.hitSlop, this.hitSlop, this.hitSlop, this.hitSlop, null, null]
883
+ : this.hitSlop;
884
+
926
885
  let left = 0;
927
886
  let top = 0;
928
887
  let right: number = width;
929
888
  let bottom: number = height;
930
889
 
931
- if (this.hitSlop.horizontal !== undefined) {
932
- left -= this.hitSlop.horizontal;
933
- right += this.hitSlop.horizontal;
934
- }
935
-
936
- if (this.hitSlop.vertical !== undefined) {
937
- top -= this.hitSlop.vertical;
938
- bottom += this.hitSlop.vertical;
939
- }
940
-
941
- if (this.hitSlop.left !== undefined) {
942
- left = -this.hitSlop.left;
890
+ if (slopLeft !== null) {
891
+ left = -slopLeft;
943
892
  }
944
893
 
945
- if (this.hitSlop.right !== undefined) {
946
- right = width + this.hitSlop.right;
894
+ if (slopRight !== null) {
895
+ right = width + slopRight;
947
896
  }
948
897
 
949
- if (this.hitSlop.top !== undefined) {
950
- top = -this.hitSlop.top;
898
+ if (slopTop !== null) {
899
+ top = -slopTop;
951
900
  }
952
901
 
953
- if (this.hitSlop.bottom !== undefined) {
954
- bottom = height + this.hitSlop.bottom;
902
+ if (slopBottom !== null) {
903
+ bottom = height + slopBottom;
955
904
  }
956
905
 
957
- if (this.hitSlop.width !== undefined) {
958
- if (this.hitSlop.left !== undefined) {
959
- right = left + this.hitSlop.width;
960
- } else if (this.hitSlop.right !== undefined) {
961
- left = right - this.hitSlop.width;
906
+ if (slopWidth !== null) {
907
+ if (slopLeft !== null) {
908
+ right = left + slopWidth;
909
+ } else if (slopRight !== null) {
910
+ left = right - slopWidth;
962
911
  }
963
912
  }
964
913
 
965
- if (this.hitSlop.height !== undefined) {
966
- if (this.hitSlop.top !== undefined) {
967
- bottom = top + this.hitSlop.height;
968
- } else if (this.hitSlop.bottom !== undefined) {
969
- top = bottom - this.hitSlop.height;
914
+ if (slopHeight !== null) {
915
+ if (slopTop !== null) {
916
+ bottom = top + slopHeight;
917
+ } else if (slopBottom !== null) {
918
+ top = bottom - slopHeight;
970
919
  }
971
920
  }
972
921
 
@@ -9,6 +9,7 @@ import type {
9
9
  TouchAction,
10
10
  UserSelect,
11
11
  } from '../handlers/gestureHandlerCommon';
12
+ import type { NormalizedHitSlop } from '../handlers/hitSlop';
12
13
  import type { PointerType } from '../PointerType';
13
14
  import type { State } from '../State';
14
15
  import type {
@@ -16,17 +17,6 @@ import type {
16
17
  GestureUpdateEventWithHandlerData,
17
18
  } from '../v3/types';
18
19
 
19
- export interface HitSlop {
20
- left?: number | undefined;
21
- right?: number | undefined;
22
- top?: number | undefined;
23
- bottom?: number | undefined;
24
- horizontal?: number | undefined;
25
- vertical?: number | undefined;
26
- width?: number | undefined;
27
- height?: number | undefined;
28
- }
29
-
30
20
  export interface Handler {
31
21
  handlerTag: number;
32
22
  }
@@ -35,7 +25,7 @@ type ConfigArgs =
35
25
  | number
36
26
  | boolean
37
27
  | string
38
- | HitSlop
28
+ | NormalizedHitSlop
39
29
  | UserSelect
40
30
  | TouchAction
41
31
  | ActiveCursor
@@ -49,7 +39,7 @@ export interface Config extends Record<string, ConfigArgs> {
49
39
  simultaneousHandlers?: Handler[] | null | undefined;
50
40
  waitFor?: Handler[] | null | undefined;
51
41
  blocksHandlers?: Handler[] | null | undefined;
52
- hitSlop?: HitSlop | null | undefined;
42
+ hitSlop?: NormalizedHitSlop | null | undefined;
53
43
  shouldCancelWhenOutside?: boolean | undefined;
54
44
  userSelect?: UserSelect | undefined;
55
45
  activeCursor?: ActiveCursor | undefined;