react-native-gesture-handler 2.18.0 → 2.19.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 (141) hide show
  1. package/README.md +1 -0
  2. package/android/build.gradle +4 -17
  3. package/android/src/main/AndroidManifest.xml +1 -3
  4. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +5 -0
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
  11. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
  12. package/android/src/main/jni/cpp-adapter.cpp +2 -4
  13. package/apple/Handlers/RNFlingHandler.h +1 -0
  14. package/apple/Handlers/RNFlingHandler.m +153 -19
  15. package/apple/Handlers/RNHoverHandler.m +44 -2
  16. package/apple/Handlers/RNLongPressHandler.m +109 -20
  17. package/apple/Handlers/RNManualHandler.m +53 -29
  18. package/apple/Handlers/RNNativeViewHandler.mm +22 -15
  19. package/apple/RNGHUIKit.h +2 -0
  20. package/apple/RNGHVector.h +31 -0
  21. package/apple/RNGHVector.m +67 -0
  22. package/apple/RNGestureHandler.h +7 -0
  23. package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
  24. package/apple/RNGestureHandlerButtonComponentView.mm +6 -0
  25. package/apple/RNGestureHandlerDirection.h +25 -0
  26. package/apple/RNGestureHandlerModule.mm +2 -4
  27. package/lib/commonjs/PointerType.js +2 -1
  28. package/lib/commonjs/PointerType.js.map +1 -1
  29. package/lib/commonjs/components/Pressable/Pressable.js +67 -70
  30. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  31. package/lib/commonjs/components/Pressable/index.js +0 -8
  32. package/lib/commonjs/components/Pressable/index.js.map +1 -1
  33. package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
  34. package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
  35. package/lib/commonjs/components/Swipeable.js +5 -0
  36. package/lib/commonjs/components/Swipeable.js.map +1 -1
  37. package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
  38. package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
  39. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
  40. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
  41. package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
  42. package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
  43. package/lib/commonjs/mocks.js +16 -3
  44. package/lib/commonjs/mocks.js.map +1 -1
  45. package/lib/commonjs/utils.js +4 -0
  46. package/lib/commonjs/utils.js.map +1 -1
  47. package/lib/commonjs/web/constants.js +3 -3
  48. package/lib/commonjs/web/constants.js.map +1 -1
  49. package/lib/commonjs/web/handlers/GestureHandler.js +1 -0
  50. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  51. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
  52. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  53. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
  54. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  55. package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
  56. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  57. package/lib/commonjs/web/interfaces.js.map +1 -1
  58. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -8
  59. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  60. package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
  61. package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
  62. package/lib/commonjs/web/tools/Vector.js +4 -2
  63. package/lib/commonjs/web/tools/Vector.js.map +1 -1
  64. package/lib/commonjs/web/utils.js +14 -13
  65. package/lib/commonjs/web/utils.js.map +1 -1
  66. package/lib/module/PointerType.js +2 -1
  67. package/lib/module/PointerType.js.map +1 -1
  68. package/lib/module/components/Pressable/Pressable.js +66 -70
  69. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  70. package/lib/module/components/Pressable/index.js +0 -1
  71. package/lib/module/components/Pressable/index.js.map +1 -1
  72. package/lib/module/components/ReanimatedSwipeable.js +58 -37
  73. package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
  74. package/lib/module/components/Swipeable.js +6 -0
  75. package/lib/module/components/Swipeable.js.map +1 -1
  76. package/lib/module/handlers/LongPressGestureHandler.js +1 -1
  77. package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
  78. package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
  79. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
  80. package/lib/module/handlers/gestures/longPressGesture.js +10 -0
  81. package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
  82. package/lib/module/mocks.js +13 -3
  83. package/lib/module/mocks.js.map +1 -1
  84. package/lib/module/utils.js +1 -0
  85. package/lib/module/utils.js.map +1 -1
  86. package/lib/module/web/constants.js +1 -1
  87. package/lib/module/web/constants.js.map +1 -1
  88. package/lib/module/web/handlers/GestureHandler.js +1 -0
  89. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  90. package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
  91. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  92. package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
  93. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  94. package/lib/module/web/handlers/PanGestureHandler.js +4 -0
  95. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  96. package/lib/module/web/interfaces.js.map +1 -1
  97. package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -8
  98. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  99. package/lib/module/web/tools/KeyboardEventManager.js +96 -0
  100. package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
  101. package/lib/module/web/tools/Vector.js +5 -3
  102. package/lib/module/web/tools/Vector.js.map +1 -1
  103. package/lib/module/web/utils.js +14 -13
  104. package/lib/module/web/utils.js.map +1 -1
  105. package/lib/typescript/PointerType.d.ts +2 -1
  106. package/lib/typescript/components/Pressable/index.d.ts +1 -1
  107. package/lib/typescript/components/Swipeable.d.ts +5 -0
  108. package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
  109. package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
  110. package/lib/typescript/mocks.d.ts +4 -3
  111. package/lib/typescript/utils.d.ts +1 -0
  112. package/lib/typescript/web/constants.d.ts +1 -1
  113. package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
  114. package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
  115. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
  116. package/lib/typescript/web/interfaces.d.ts +1 -1
  117. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
  118. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
  119. package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
  120. package/package.json +3 -3
  121. package/src/PointerType.ts +1 -0
  122. package/src/components/Pressable/Pressable.tsx +70 -50
  123. package/src/components/Pressable/index.ts +1 -1
  124. package/src/components/ReanimatedSwipeable.tsx +70 -47
  125. package/src/components/Swipeable.tsx +6 -0
  126. package/src/handlers/LongPressGestureHandler.ts +6 -0
  127. package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
  128. package/src/handlers/gestures/longPressGesture.ts +9 -0
  129. package/src/{mocks.ts → mocks.tsx} +8 -3
  130. package/src/utils.ts +2 -0
  131. package/src/web/constants.ts +1 -1
  132. package/src/web/handlers/GestureHandler.ts +3 -1
  133. package/src/web/handlers/LongPressGestureHandler.ts +49 -10
  134. package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
  135. package/src/web/handlers/PanGestureHandler.ts +4 -0
  136. package/src/web/interfaces.ts +1 -1
  137. package/src/web/tools/GestureHandlerDelegate.ts +1 -0
  138. package/src/web/tools/GestureHandlerWebDelegate.ts +67 -8
  139. package/src/web/tools/KeyboardEventManager.ts +91 -0
  140. package/src/web/tools/Vector.ts +4 -3
  141. package/src/web/utils.ts +15 -13
@@ -11,6 +11,7 @@ exports.PointerType = PointerType;
11
11
  PointerType[PointerType["TOUCH"] = 0] = "TOUCH";
12
12
  PointerType[PointerType["STYLUS"] = 1] = "STYLUS";
13
13
  PointerType[PointerType["MOUSE"] = 2] = "MOUSE";
14
- PointerType[PointerType["OTHER"] = 3] = "OTHER";
14
+ PointerType[PointerType["KEY"] = 3] = "KEY";
15
+ PointerType[PointerType["OTHER"] = 4] = "OTHER";
15
16
  })(PointerType || (exports.PointerType = PointerType = {}));
16
17
  //# sourceMappingURL=PointerType.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["PointerType.ts"],"names":["PointerType"],"mappings":";;;;;;IAAYA,W;;;WAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;GAAAA,W,2BAAAA,W","sourcesContent":["export enum PointerType {\n TOUCH,\n STYLUS,\n MOUSE,\n OTHER,\n}\n"]}
1
+ {"version":3,"sources":["PointerType.ts"],"names":["PointerType"],"mappings":";;;;;;IAAYA,W;;;WAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;GAAAA,W,2BAAAA,W","sourcesContent":["export enum PointerType {\n TOUCH,\n STYLUS,\n MOUSE,\n KEY,\n OTHER,\n}\n"]}
@@ -19,78 +19,81 @@ var _utils = require("./utils");
19
19
 
20
20
  var _PressabilityDebugView = require("../../handlers/PressabilityDebugView");
21
21
 
22
+ var _utils2 = require("../../utils");
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
25
27
 
26
28
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
29
 
30
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
31
+
28
32
  const DEFAULT_LONG_PRESS_DURATION = 500;
29
33
 
30
34
  function Pressable(props) {
31
- var _props$testOnly_press, _props$delayLongPress, _props$unstable_press, _props$android_disabl, _props$android_ripple, _props$android_ripple2, _props$android_ripple3, _props$android_ripple4;
32
-
33
- const [pressedState, setPressedState] = (0, _react.useState)((_props$testOnly_press = props.testOnly_pressed) !== null && _props$testOnly_press !== void 0 ? _props$testOnly_press : false);
35
+ var _android_ripple$color, _android_ripple$radiu;
36
+
37
+ const {
38
+ testOnly_pressed,
39
+ hitSlop,
40
+ pressRetentionOffset,
41
+ delayHoverIn,
42
+ onHoverIn,
43
+ delayHoverOut,
44
+ onHoverOut,
45
+ delayLongPress,
46
+ unstable_pressDelay,
47
+ onPress,
48
+ onPressIn,
49
+ onPressOut,
50
+ onLongPress,
51
+ style,
52
+ children,
53
+ android_disableSound,
54
+ android_ripple,
55
+ disabled,
56
+ ...remainingProps
57
+ } = props;
58
+ const [pressedState, setPressedState] = (0, _react.useState)(testOnly_pressed !== null && testOnly_pressed !== void 0 ? testOnly_pressed : false);
34
59
  const pressableRef = (0, _react.useRef)(null); // Disabled when onLongPress has been called
35
60
 
36
61
  const isPressCallbackEnabled = (0, _react.useRef)(true);
37
62
  const hasPassedBoundsChecks = (0, _react.useRef)(false);
38
63
  const shouldPreventNativeEffects = (0, _react.useRef)(false);
39
- const normalizedHitSlop = (0, _react.useMemo)(() => {
40
- var _props$hitSlop;
41
-
42
- return typeof props.hitSlop === 'number' ? (0, _utils.numberAsInset)(props.hitSlop) : (_props$hitSlop = props.hitSlop) !== null && _props$hitSlop !== void 0 ? _props$hitSlop : {};
43
- }, [props.hitSlop]);
44
- const normalizedPressRetentionOffset = (0, _react.useMemo)(() => {
45
- var _props$pressRetention;
46
-
47
- return typeof props.pressRetentionOffset === 'number' ? (0, _utils.numberAsInset)(props.pressRetentionOffset) : (_props$pressRetention = props.pressRetentionOffset) !== null && _props$pressRetention !== void 0 ? _props$pressRetention : {};
48
- }, [props.pressRetentionOffset]);
64
+ const normalizedHitSlop = (0, _react.useMemo)(() => typeof hitSlop === 'number' ? (0, _utils.numberAsInset)(hitSlop) : hitSlop !== null && hitSlop !== void 0 ? hitSlop : {}, [hitSlop]);
65
+ const normalizedPressRetentionOffset = (0, _react.useMemo)(() => typeof pressRetentionOffset === 'number' ? (0, _utils.numberAsInset)(pressRetentionOffset) : pressRetentionOffset !== null && pressRetentionOffset !== void 0 ? pressRetentionOffset : {}, [pressRetentionOffset]);
49
66
  const hoverInTimeout = (0, _react.useRef)(null);
50
67
  const hoverOutTimeout = (0, _react.useRef)(null);
51
68
  const hoverGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.Hover().manualActivation(true) // Stops Hover from blocking Native gesture activation on web
52
69
  .cancelsTouchesInView(false).onBegin(event => {
53
- var _props$onHoverIn2;
54
-
55
70
  if (hoverOutTimeout.current) {
56
71
  clearTimeout(hoverOutTimeout.current);
57
72
  }
58
73
 
59
- if (props.delayHoverIn) {
60
- hoverInTimeout.current = setTimeout(() => {
61
- var _props$onHoverIn;
62
-
63
- return (_props$onHoverIn = props.onHoverIn) === null || _props$onHoverIn === void 0 ? void 0 : _props$onHoverIn.call(props, (0, _utils.gestureToPressableEvent)(event));
64
- }, props.delayHoverIn);
74
+ if (delayHoverIn) {
75
+ hoverInTimeout.current = setTimeout(() => onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn((0, _utils.gestureToPressableEvent)(event)), delayHoverIn);
65
76
  return;
66
77
  }
67
78
 
68
- (_props$onHoverIn2 = props.onHoverIn) === null || _props$onHoverIn2 === void 0 ? void 0 : _props$onHoverIn2.call(props, (0, _utils.gestureToPressableEvent)(event));
79
+ onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn((0, _utils.gestureToPressableEvent)(event));
69
80
  }).onFinalize(event => {
70
- var _props$onHoverOut2;
71
-
72
81
  if (hoverInTimeout.current) {
73
82
  clearTimeout(hoverInTimeout.current);
74
83
  }
75
84
 
76
- if (props.delayHoverOut) {
77
- hoverOutTimeout.current = setTimeout(() => {
78
- var _props$onHoverOut;
79
-
80
- return (_props$onHoverOut = props.onHoverOut) === null || _props$onHoverOut === void 0 ? void 0 : _props$onHoverOut.call(props, (0, _utils.gestureToPressableEvent)(event));
81
- }, props.delayHoverOut);
85
+ if (delayHoverOut) {
86
+ hoverOutTimeout.current = setTimeout(() => onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut((0, _utils.gestureToPressableEvent)(event)), delayHoverOut);
82
87
  return;
83
88
  }
84
89
 
85
- (_props$onHoverOut2 = props.onHoverOut) === null || _props$onHoverOut2 === void 0 ? void 0 : _props$onHoverOut2.call(props, (0, _utils.gestureToPressableEvent)(event));
86
- }), [props]);
90
+ onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut((0, _utils.gestureToPressableEvent)(event));
91
+ }), [delayHoverIn, delayHoverOut, onHoverIn, onHoverOut]);
87
92
  const pressDelayTimeoutRef = (0, _react.useRef)(null);
88
93
  const isTouchPropagationAllowed = (0, _react.useRef)(false); // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use
89
94
 
90
95
  const deferredEventPayload = (0, _react.useRef)(null);
91
96
  const pressInHandler = (0, _react.useCallback)(event => {
92
- var _props$onPressIn;
93
-
94
97
  if (handlingOnTouchesDown.current) {
95
98
  deferredEventPayload.current = event;
96
99
  }
@@ -100,19 +103,17 @@ function Pressable(props) {
100
103
  }
101
104
 
102
105
  deferredEventPayload.current = null;
103
- (_props$onPressIn = props.onPressIn) === null || _props$onPressIn === void 0 ? void 0 : _props$onPressIn.call(props, event);
106
+ onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(event);
104
107
  isPressCallbackEnabled.current = true;
105
108
  pressDelayTimeoutRef.current = null;
106
109
  setPressedState(true);
107
- }, [props]);
110
+ }, [onPressIn]);
108
111
  const pressOutHandler = (0, _react.useCallback)(event => {
109
- var _props$onPressOut;
110
-
111
112
  if (!hasPassedBoundsChecks.current || event.nativeEvent.touches.length > event.nativeEvent.changedTouches.length) {
112
113
  return;
113
114
  }
114
115
 
115
- if (props.unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
116
+ if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
116
117
  // When delay is preemptively finished by lifting touches,
117
118
  // we want to immediately activate it's effects - pressInHandler,
118
119
  // even though we are located at the pressOutHandler
@@ -121,18 +122,14 @@ function Pressable(props) {
121
122
  }
122
123
 
123
124
  if (deferredEventPayload.current) {
124
- var _props$onPressIn2;
125
-
126
- (_props$onPressIn2 = props.onPressIn) === null || _props$onPressIn2 === void 0 ? void 0 : _props$onPressIn2.call(props, deferredEventPayload.current);
125
+ onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(deferredEventPayload.current);
127
126
  deferredEventPayload.current = null;
128
127
  }
129
128
 
130
- (_props$onPressOut = props.onPressOut) === null || _props$onPressOut === void 0 ? void 0 : _props$onPressOut.call(props, event);
129
+ onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
131
130
 
132
131
  if (isPressCallbackEnabled.current) {
133
- var _props$onPress;
134
-
135
- (_props$onPress = props.onPress) === null || _props$onPress === void 0 ? void 0 : _props$onPress.call(props, event);
132
+ onPress === null || onPress === void 0 ? void 0 : onPress(event);
136
133
  }
137
134
 
138
135
  if (longPressTimeoutRef.current) {
@@ -144,7 +141,7 @@ function Pressable(props) {
144
141
  hasPassedBoundsChecks.current = false;
145
142
  isPressCallbackEnabled.current = true;
146
143
  setPressedState(false);
147
- }, [pressInHandler, props]);
144
+ }, [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]);
148
145
  const handlingOnTouchesDown = (0, _react.useRef)(false);
149
146
  const onEndHandlingTouchesDown = (0, _react.useRef)(null);
150
147
  const cancelledMidPress = (0, _react.useRef)(false);
@@ -154,9 +151,7 @@ function Pressable(props) {
154
151
  }
155
152
 
156
153
  if (hasPassedBoundsChecks.current) {
157
- var _props$onLongPress;
158
-
159
- (_props$onLongPress = props.onLongPress) === null || _props$onLongPress === void 0 ? void 0 : _props$onLongPress.call(props, (0, _utils.gestureTouchToPressableEvent)(event));
154
+ onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress((0, _utils.gestureTouchToPressableEvent)(event));
160
155
  isPressCallbackEnabled.current = false;
161
156
  }
162
157
 
@@ -164,11 +159,11 @@ function Pressable(props) {
164
159
  clearTimeout(longPressTimeoutRef.current);
165
160
  longPressTimeoutRef.current = null;
166
161
  }
167
- }, [props]);
162
+ }, [onLongPress]);
168
163
  const longPressTimeoutRef = (0, _react.useRef)(null);
169
- const longPressMinDuration = ((_props$delayLongPress = props.delayLongPress) !== null && _props$delayLongPress !== void 0 ? _props$delayLongPress : DEFAULT_LONG_PRESS_DURATION) + ((_props$unstable_press = props.unstable_pressDelay) !== null && _props$unstable_press !== void 0 ? _props$unstable_press : 0);
170
- const pressAndTouchGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.LongPress().minDuration(Number.MAX_SAFE_INTEGER) // Stops long press from blocking native gesture
171
- .maxDistance(Number.MAX_SAFE_INTEGER) // Stops long press from cancelling after set distance
164
+ const longPressMinDuration = (delayLongPress !== null && delayLongPress !== void 0 ? delayLongPress : DEFAULT_LONG_PRESS_DURATION) + (unstable_pressDelay !== null && unstable_pressDelay !== void 0 ? unstable_pressDelay : 0);
165
+ const pressAndTouchGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.LongPress().minDuration(_utils2.INT32_MAX) // Stops long press from blocking native gesture
166
+ .maxDistance(_utils2.INT32_MAX) // Stops long press from cancelling after set distance
172
167
  .cancelsTouchesInView(false).onTouchesDown(event => {
173
168
  var _pressableRef$current;
174
169
 
@@ -193,10 +188,10 @@ function Pressable(props) {
193
188
  longPressTimeoutRef.current = setTimeout(() => activateLongPress(event), longPressMinDuration);
194
189
  }
195
190
 
196
- if (props.unstable_pressDelay) {
191
+ if (unstable_pressDelay) {
197
192
  pressDelayTimeoutRef.current = setTimeout(() => {
198
193
  pressInHandler((0, _utils.gestureTouchToPressableEvent)(event));
199
- }, props.unstable_pressDelay);
194
+ }, unstable_pressDelay);
200
195
  } else {
201
196
  pressInHandler((0, _utils.gestureTouchToPressableEvent)(event));
202
197
  }
@@ -235,7 +230,7 @@ function Pressable(props) {
235
230
  }
236
231
 
237
232
  pressOutHandler((0, _utils.gestureTouchToPressableEvent)(event));
238
- }), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler, props.unstable_pressDelay]); // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events
233
+ }), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler, unstable_pressDelay]); // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events
239
234
 
240
235
  const buttonGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.Native().onBegin(() => {
241
236
  // Android sets BEGAN state on press down
@@ -279,7 +274,7 @@ function Pressable(props) {
279
274
  isTouchPropagationAllowed.current = true;
280
275
  }), [pressInHandler, pressOutHandler]);
281
276
  const appliedHitSlop = (0, _utils.addInsets)(normalizedHitSlop, normalizedPressRetentionOffset);
282
- const isPressableEnabled = props.disabled !== true;
277
+ const isPressableEnabled = disabled !== true;
283
278
  const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];
284
279
 
285
280
  for (const gesture of gestures) {
@@ -298,34 +293,36 @@ function Pressable(props) {
298
293
 
299
294
  const gesture = _gestureObjects.GestureObjects.Simultaneous(...gestures);
300
295
 
301
- const defaultRippleColor = props.android_ripple ? undefined : 'transparent'; // `cursor: 'pointer'` on `RNButton` crashes iOS
296
+ const defaultRippleColor = android_ripple ? undefined : 'transparent'; // `cursor: 'pointer'` on `RNButton` crashes iOS
302
297
 
303
298
  const pointerStyle = _reactNative.Platform.OS === 'web' ? {
304
299
  cursor: 'pointer'
305
300
  } : {};
306
- const styleProp = typeof props.style === 'function' ? props.style({
301
+ const styleProp = typeof style === 'function' ? style({
307
302
  pressed: pressedState
308
- }) : props.style;
309
- const childrenProp = typeof props.children === 'function' ? props.children({
303
+ }) : style;
304
+ const childrenProp = typeof children === 'function' ? children({
310
305
  pressed: pressedState
311
- }) : props.children;
306
+ }) : children;
312
307
 
313
308
  const flattenedStyles = _reactNative.StyleSheet.flatten(styleProp !== null && styleProp !== void 0 ? styleProp : {});
314
309
 
315
310
  const [innerStyles, outerStyles] = (0, _utils.splitStyles)(flattenedStyles);
316
- return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
311
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({}, remainingProps, {
317
312
  style: outerStyles
318
- }, /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
313
+ }), /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
319
314
  gesture: gesture
320
315
  }, /*#__PURE__*/_react.default.createElement(_GestureHandlerButton.default, {
321
316
  ref: pressableRef,
322
- testID: props.testID,
323
317
  hitSlop: appliedHitSlop,
324
318
  enabled: isPressableEnabled,
325
- touchSoundDisabled: (_props$android_disabl = props.android_disableSound) !== null && _props$android_disabl !== void 0 ? _props$android_disabl : undefined,
326
- rippleColor: (0, _reactNative.processColor)((_props$android_ripple = (_props$android_ripple2 = props.android_ripple) === null || _props$android_ripple2 === void 0 ? void 0 : _props$android_ripple2.color) !== null && _props$android_ripple !== void 0 ? _props$android_ripple : defaultRippleColor),
327
- rippleRadius: (_props$android_ripple3 = (_props$android_ripple4 = props.android_ripple) === null || _props$android_ripple4 === void 0 ? void 0 : _props$android_ripple4.radius) !== null && _props$android_ripple3 !== void 0 ? _props$android_ripple3 : undefined,
328
- style: [_reactNative.StyleSheet.absoluteFill, pointerStyle, innerStyles]
319
+ touchSoundDisabled: android_disableSound !== null && android_disableSound !== void 0 ? android_disableSound : undefined,
320
+ rippleColor: (0, _reactNative.processColor)((_android_ripple$color = android_ripple === null || android_ripple === void 0 ? void 0 : android_ripple.color) !== null && _android_ripple$color !== void 0 ? _android_ripple$color : defaultRippleColor),
321
+ rippleRadius: (_android_ripple$radiu = android_ripple === null || android_ripple === void 0 ? void 0 : android_ripple.radius) !== null && _android_ripple$radiu !== void 0 ? _android_ripple$radiu : undefined,
322
+ style: [{
323
+ width: '100%',
324
+ height: '100%'
325
+ }, pointerStyle, innerStyles]
329
326
  }, childrenProp, __DEV__ ? /*#__PURE__*/_react.default.createElement(_PressabilityDebugView.PressabilityDebugView, {
330
327
  color: "red",
331
328
  hitSlop: normalizedHitSlop
@@ -1 +1 @@
1
- {"version":3,"sources":["Pressable.tsx"],"names":["DEFAULT_LONG_PRESS_DURATION","Pressable","props","pressedState","setPressedState","testOnly_pressed","pressableRef","isPressCallbackEnabled","hasPassedBoundsChecks","shouldPreventNativeEffects","normalizedHitSlop","hitSlop","normalizedPressRetentionOffset","pressRetentionOffset","hoverInTimeout","hoverOutTimeout","hoverGesture","Gesture","Hover","manualActivation","cancelsTouchesInView","onBegin","event","current","clearTimeout","delayHoverIn","setTimeout","onHoverIn","onFinalize","delayHoverOut","onHoverOut","pressDelayTimeoutRef","isTouchPropagationAllowed","deferredEventPayload","pressInHandler","handlingOnTouchesDown","onPressIn","pressOutHandler","nativeEvent","touches","length","changedTouches","unstable_pressDelay","onPressOut","onPress","longPressTimeoutRef","onEndHandlingTouchesDown","cancelledMidPress","activateLongPress","onLongPress","longPressMinDuration","delayLongPress","pressAndTouchGesture","LongPress","minDuration","Number","MAX_SAFE_INTEGER","maxDistance","onTouchesDown","measure","_x","_y","width","height","at","onTouchesUp","onTouchesCancelled","allTouches","buttonGesture","Native","Platform","OS","onStart","appliedHitSlop","isPressableEnabled","disabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","android_ripple","undefined","pointerStyle","cursor","styleProp","style","pressed","childrenProp","children","flattenedStyles","StyleSheet","flatten","innerStyles","outerStyles","testID","android_disableSound","color","radius","absoluteFill","__DEV__"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AASA;;AACA;;AAQA;;;;;;;;AAGA,MAAMA,2BAA2B,GAAG,GAApC;;AAEe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;AAAA;;AACvD,QAAM,CAACC,YAAD,EAAeC,eAAf,IAAkC,8CACtCF,KAAK,CAACG,gBADgC,yEACZ,KADY,CAAxC;AAIA,QAAMC,YAAY,GAAG,mBAAa,IAAb,CAArB,CALuD,CAOvD;;AACA,QAAMC,sBAAsB,GAAG,mBAA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AAA,MAAM,EAAEJ,KAAK,CAAC+F,MAFhB;AAGE,IAAA,OAAO,EAAExB,cAHX;AAIE,IAAA,OAAO,EAAEC,kBAJX;AAKE,IAAA,kBAAkB,2BAAExE,KAAK,CAACgG,oBAAR,yEAAgCd,SALpD;AAME,IAAA,WAAW,EAAE,kFACXlF,KAAK,CAACiF,cADK,2DACX,uBAAsBgB,KADX,yEACoBjB,kBADpB,CANf;AASE,IAAA,YAAY,sDAAEhF,KAAK,CAACiF,cAAR,2DAAE,uBAAsBiB,MAAxB,2EAAkChB,SAThD;AAUE,IAAA,KAAK,EAAE,CAACS,wBAAWQ,YAAZ,EAA0BhB,YAA1B,EAAwCU,WAAxC;AAVT,KAWGL,YAXH,EAYGY,OAAO,gBACN,6BAAC,4CAAD;AAAuB,IAAA,KAAK,EAAC,KAA7B;AAAmC,IAAA,OAAO,EAAE5F;AAA5C,IADM,GAEJ,IAdN,CADF,CADF,CADF;AAsBD","sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../../handlers/gestures/GestureDetector';\nimport { PressableEvent, PressableProps } from './PressableProps';\nimport {\n Insets,\n Platform,\n StyleProp,\n View,\n ViewStyle,\n processColor,\n StyleSheet,\n} from 'react-native';\nimport NativeButton from '../GestureHandlerButton';\nimport {\n numberAsInset,\n gestureToPressableEvent,\n isTouchWithinInset,\n gestureTouchToPressableEvent,\n addInsets,\n splitStyles,\n} from './utils';\nimport { PressabilityDebugView } from '../../handlers/PressabilityDebugView';\nimport { GestureTouchEvent } from '../../handlers/gestureHandlerCommon';\n\nconst DEFAULT_LONG_PRESS_DURATION = 500;\n\nexport default function Pressable(props: PressableProps) {\n const [pressedState, setPressedState] = useState(\n props.testOnly_pressed ?? false\n );\n\n const pressableRef = useRef<View>(null);\n\n // Disabled when onLongPress has been called\n const isPressCallbackEnabled = useRef<boolean>(true);\n const hasPassedBoundsChecks = useRef<boolean>(false);\n const shouldPreventNativeEffects = useRef<boolean>(false);\n\n const normalizedHitSlop: Insets = useMemo(\n () =>\n typeof props.hitSlop === 'number'\n ? numberAsInset(props.hitSlop)\n : props.hitSlop ?? {},\n [props.hitSlop]\n );\n\n const normalizedPressRetentionOffset: Insets = useMemo(\n () =>\n typeof props.pressRetentionOffset === 'number'\n ? numberAsInset(props.pressRetentionOffset)\n : props.pressRetentionOffset ?? {},\n [props.pressRetentionOffset]\n );\n\n const hoverInTimeout = useRef<number | null>(null);\n const hoverOutTimeout = useRef<number | null>(null);\n\n const hoverGesture = useMemo(\n () =>\n Gesture.Hover()\n .manualActivation(true) // Stops Hover from blocking Native gesture activation on web\n .cancelsTouchesInView(false)\n .onBegin((event) => {\n if (hoverOutTimeout.current) {\n clearTimeout(hoverOutTimeout.current);\n }\n if (props.delayHoverIn) {\n hoverInTimeout.current = setTimeout(\n () => props.onHoverIn?.(gestureToPressableEvent(event)),\n props.delayHoverIn\n );\n return;\n }\n props.onHoverIn?.(gestureToPressableEvent(event));\n })\n .onFinalize((event) => {\n if (hoverInTimeout.current) {\n clearTimeout(hoverInTimeout.current);\n }\n if (props.delayHoverOut) {\n hoverOutTimeout.current = setTimeout(\n () => props.onHoverOut?.(gestureToPressableEvent(event)),\n props.delayHoverOut\n );\n return;\n }\n props.onHoverOut?.(gestureToPressableEvent(event));\n }),\n [props]\n );\n\n const pressDelayTimeoutRef = useRef<number | null>(null);\n const isTouchPropagationAllowed = useRef<boolean>(false);\n\n // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use\n const deferredEventPayload = useRef<PressableEvent | null>(null);\n\n const pressInHandler = useCallback(\n (event: PressableEvent) => {\n if (handlingOnTouchesDown.current) {\n deferredEventPayload.current = event;\n }\n\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n deferredEventPayload.current = null;\n\n props.onPressIn?.(event);\n isPressCallbackEnabled.current = true;\n pressDelayTimeoutRef.current = null;\n setPressedState(true);\n },\n [props]\n );\n\n const pressOutHandler = useCallback(\n (event: PressableEvent) => {\n if (\n !hasPassedBoundsChecks.current ||\n event.nativeEvent.touches.length >\n event.nativeEvent.changedTouches.length\n ) {\n return;\n }\n\n if (props.unstable_pressDelay && pressDelayTimeoutRef.current !== null) {\n // When delay is preemptively finished by lifting touches,\n // we want to immediately activate it's effects - pressInHandler,\n // even though we are located at the pressOutHandler\n clearTimeout(pressDelayTimeoutRef.current);\n pressInHandler(event);\n }\n\n if (deferredEventPayload.current) {\n props.onPressIn?.(deferredEventPayload.current);\n deferredEventPayload.current = null;\n }\n\n props.onPressOut?.(event);\n\n if (isPressCallbackEnabled.current) {\n props.onPress?.(event);\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n\n isTouchPropagationAllowed.current = false;\n hasPassedBoundsChecks.current = false;\n isPressCallbackEnabled.current = true;\n setPressedState(false);\n },\n [pressInHandler, props]\n );\n\n const handlingOnTouchesDown = useRef<boolean>(false);\n const onEndHandlingTouchesDown = useRef<(() => void) | null>(null);\n const cancelledMidPress = useRef<boolean>(false);\n\n const activateLongPress = useCallback(\n (event: GestureTouchEvent) => {\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n props.onLongPress?.(gestureTouchToPressableEvent(event));\n isPressCallbackEnabled.current = false;\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n },\n [props]\n );\n\n const longPressTimeoutRef = useRef<number | null>(null);\n const longPressMinDuration =\n (props.delayLongPress ?? DEFAULT_LONG_PRESS_DURATION) +\n (props.unstable_pressDelay ?? 0);\n\n const pressAndTouchGesture = useMemo(\n () =>\n Gesture.LongPress()\n .minDuration(Number.MAX_SAFE_INTEGER) // Stops long press from blocking native gesture\n .maxDistance(Number.MAX_SAFE_INTEGER) // Stops long press from cancelling after set distance\n .cancelsTouchesInView(false)\n .onTouchesDown((event) => {\n handlingOnTouchesDown.current = true;\n pressableRef.current?.measure((_x, _y, width, height) => {\n if (\n !isTouchWithinInset(\n {\n width,\n height,\n },\n normalizedHitSlop,\n event.changedTouches.at(-1)\n ) ||\n hasPassedBoundsChecks.current ||\n cancelledMidPress.current\n ) {\n cancelledMidPress.current = false;\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n return;\n }\n\n hasPassedBoundsChecks.current = true;\n\n // In case of multiple touches, the first one starts long press gesture\n if (longPressTimeoutRef.current === null) {\n // Start long press gesture timer\n longPressTimeoutRef.current = setTimeout(\n () => activateLongPress(event),\n longPressMinDuration\n );\n }\n\n if (props.unstable_pressDelay) {\n pressDelayTimeoutRef.current = setTimeout(() => {\n pressInHandler(gestureTouchToPressableEvent(event));\n }, props.unstable_pressDelay);\n } else {\n pressInHandler(gestureTouchToPressableEvent(event));\n }\n\n onEndHandlingTouchesDown.current?.();\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n });\n })\n .onTouchesUp((event) => {\n if (handlingOnTouchesDown.current) {\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n // On iOS, short taps will make LongPress gesture call onTouchesUp before Native gesture calls onStart\n // This variable ensures that onStart isn't detected as the first gesture since Pressable is pressed.\n if (deferredEventPayload.current !== null) {\n shouldPreventNativeEffects.current = true;\n }\n pressOutHandler(gestureTouchToPressableEvent(event));\n })\n .onTouchesCancelled((event) => {\n isPressCallbackEnabled.current = false;\n\n if (handlingOnTouchesDown.current) {\n cancelledMidPress.current = true;\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n\n if (\n !hasPassedBoundsChecks.current ||\n event.allTouches.length > event.changedTouches.length\n ) {\n return;\n }\n\n pressOutHandler(gestureTouchToPressableEvent(event));\n }),\n [\n activateLongPress,\n longPressMinDuration,\n normalizedHitSlop,\n pressInHandler,\n pressOutHandler,\n props.unstable_pressDelay,\n ]\n );\n\n // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events\n const buttonGesture = useMemo(\n () =>\n Gesture.Native()\n .onBegin(() => {\n // Android sets BEGAN state on press down\n if (Platform.OS === 'android') {\n isTouchPropagationAllowed.current = true;\n }\n })\n .onStart(() => {\n if (Platform.OS === 'web') {\n isTouchPropagationAllowed.current = true;\n }\n\n // iOS sets ACTIVE state on press down\n if (Platform.OS !== 'ios') {\n return;\n }\n\n if (deferredEventPayload.current) {\n isTouchPropagationAllowed.current = true;\n\n if (hasPassedBoundsChecks.current) {\n pressInHandler(deferredEventPayload.current);\n deferredEventPayload.current = null;\n } else {\n pressOutHandler(deferredEventPayload.current);\n isTouchPropagationAllowed.current = false;\n }\n\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n isTouchPropagationAllowed.current = true;\n return;\n }\n\n if (shouldPreventNativeEffects.current) {\n shouldPreventNativeEffects.current = false;\n return;\n }\n\n isTouchPropagationAllowed.current = true;\n }),\n [pressInHandler, pressOutHandler]\n );\n\n const appliedHitSlop = addInsets(\n normalizedHitSlop,\n normalizedPressRetentionOffset\n );\n\n const isPressableEnabled = props.disabled !== true;\n\n const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];\n\n for (const gesture of gestures) {\n gesture.enabled(isPressableEnabled);\n gesture.runOnJS(true);\n gesture.hitSlop(appliedHitSlop);\n gesture.shouldCancelWhenOutside(false);\n\n if (Platform.OS !== 'web') {\n gesture.shouldCancelWhenOutside(true);\n }\n }\n\n // Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area\n buttonGesture.hitSlop(normalizedHitSlop);\n\n const gesture = Gesture.Simultaneous(...gestures);\n\n const defaultRippleColor = props.android_ripple ? undefined : 'transparent';\n\n // `cursor: 'pointer'` on `RNButton` crashes iOS\n const pointerStyle: StyleProp<ViewStyle> =\n Platform.OS === 'web' ? { cursor: 'pointer' } : {};\n\n const styleProp =\n typeof props.style === 'function'\n ? props.style({ pressed: pressedState })\n : props.style;\n\n const childrenProp =\n typeof props.children === 'function'\n ? props.children({ pressed: pressedState })\n : props.children;\n\n const flattenedStyles = StyleSheet.flatten(styleProp ?? {});\n\n const [innerStyles, outerStyles] = splitStyles(flattenedStyles);\n\n return (\n <View style={outerStyles}>\n <GestureDetector gesture={gesture}>\n <NativeButton\n ref={pressableRef}\n testID={props.testID}\n hitSlop={appliedHitSlop}\n enabled={isPressableEnabled}\n touchSoundDisabled={props.android_disableSound ?? undefined}\n rippleColor={processColor(\n props.android_ripple?.color ?? defaultRippleColor\n )}\n rippleRadius={props.android_ripple?.radius ?? undefined}\n style={[StyleSheet.absoluteFill, pointerStyle, innerStyles]}>\n {childrenProp}\n {__DEV__ ? (\n <PressabilityDebugView color=\"red\" hitSlop={normalizedHitSlop} />\n ) : null}\n </NativeButton>\n </GestureDetector>\n </View>\n );\n}\n"]}
1
+ {"version":3,"sources":["Pressable.tsx"],"names":["DEFAULT_LONG_PRESS_DURATION","Pressable","props","testOnly_pressed","hitSlop","pressRetentionOffset","delayHoverIn","onHoverIn","delayHoverOut","onHoverOut","delayLongPress","unstable_pressDelay","onPress","onPressIn","onPressOut","onLongPress","style","children","android_disableSound","android_ripple","disabled","remainingProps","pressedState","setPressedState","pressableRef","isPressCallbackEnabled","hasPassedBoundsChecks","shouldPreventNativeEffects","normalizedHitSlop","normalizedPressRetentionOffset","hoverInTimeout","hoverOutTimeout","hoverGesture","Gesture","Hover","manualActivation","cancelsTouchesInView","onBegin","event","current","clearTimeout","setTimeout","onFinalize","pressDelayTimeoutRef","isTouchPropagationAllowed","deferredEventPayload","pressInHandler","handlingOnTouchesDown","pressOutHandler","nativeEvent","touches","length","changedTouches","longPressTimeoutRef","onEndHandlingTouchesDown","cancelledMidPress","activateLongPress","longPressMinDuration","pressAndTouchGesture","LongPress","minDuration","INT32_MAX","maxDistance","onTouchesDown","measure","_x","_y","width","height","at","onTouchesUp","onTouchesCancelled","allTouches","buttonGesture","Native","Platform","OS","onStart","appliedHitSlop","isPressableEnabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","undefined","pointerStyle","cursor","styleProp","pressed","childrenProp","flattenedStyles","StyleSheet","flatten","innerStyles","outerStyles","color","radius","__DEV__"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AASA;;AACA;;AAQA;;AAEA;;;;;;;;;;AAEA,MAAMA,2BAA2B,GAAG,GAApC;;AAEe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;AAAA;;AACvD,QAAM;AACJC,IAAAA,gBADI;AAEJC,IAAAA,OAFI;AAGJC,IAAAA,oBAHI;AAIJC,IAAAA,YAJI;AAKJC,IAAAA,SALI;AAMJC,IAAAA,aANI;AAOJC,IAAAA,UAPI;AAQJC,IAAAA,cARI;AASJC,IAAAA,mBATI;AAUJC,IAAAA,OAVI;AAWJC,IAAAA,SAXI;AAYJC,IAAAA,UAZI;AAaJC,IAAAA,WAbI;AAcJC,IAAAA,KAdI;AAeJC,IAAAA,QAfI;AAgBJC,IAAAA,oBAhBI;AAiBJC,IAAAA,cAjBI;AAkBJC,IAAAA,QAlBI;AAmBJ,OAAGC;AAnBC,MAoBFnB,KApBJ;AAsBA,QAAM,CAACoB,YAAD,EAAeC,eAAf,IAAkC,qBAASpB,gBAAT,aAASA,gBAAT,cAASA,gBAAT,GAA6B,KAA7B,CAAxC;AAEA,QAAMqB,YAAY,GAAG,mBAAa,IAAb,CAArB,CAzBuD,CA2BvD;;AACA,QAAMC,sBAAsB,GAAG,mBAAgB,IAAhB,CAA/B;AACA,QAAMC,qBAAqB,GAAG,mBAAgB,KAAhB,CAA9B;AACA,QAAMC,0BAA0B,GAAG,mBAAgB,KAAhB,CAAnC;AAEA,QAAMC,iBAAyB,GAAG,oBAChC,MACE,OAAOxB,OAAP,KAAmB,QAAnB,GAA8B,0BAAcA,OAAd,CAA9B,GAAuDA,OAAvD,aAAuDA,OAAvD,cAAuDA,OAAvD,GAAkE,EAFpC,EAGhC,CAACA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,IADM,GAEJ,IAjBN,CADF,CADF,CADF;AAyBD","sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../../handlers/gestures/GestureDetector';\nimport { PressableEvent, PressableProps } from './PressableProps';\nimport {\n Insets,\n Platform,\n StyleProp,\n View,\n ViewStyle,\n processColor,\n StyleSheet,\n} from 'react-native';\nimport NativeButton from '../GestureHandlerButton';\nimport {\n numberAsInset,\n gestureToPressableEvent,\n isTouchWithinInset,\n gestureTouchToPressableEvent,\n addInsets,\n splitStyles,\n} from './utils';\nimport { PressabilityDebugView } from '../../handlers/PressabilityDebugView';\nimport { GestureTouchEvent } from '../../handlers/gestureHandlerCommon';\nimport { INT32_MAX } from '../../utils';\n\nconst DEFAULT_LONG_PRESS_DURATION = 500;\n\nexport default function Pressable(props: PressableProps) {\n const {\n testOnly_pressed,\n hitSlop,\n pressRetentionOffset,\n delayHoverIn,\n onHoverIn,\n delayHoverOut,\n onHoverOut,\n delayLongPress,\n unstable_pressDelay,\n onPress,\n onPressIn,\n onPressOut,\n onLongPress,\n style,\n children,\n android_disableSound,\n android_ripple,\n disabled,\n ...remainingProps\n } = props;\n\n const [pressedState, setPressedState] = useState(testOnly_pressed ?? false);\n\n const pressableRef = useRef<View>(null);\n\n // Disabled when onLongPress has been called\n const isPressCallbackEnabled = useRef<boolean>(true);\n const hasPassedBoundsChecks = useRef<boolean>(false);\n const shouldPreventNativeEffects = useRef<boolean>(false);\n\n const normalizedHitSlop: Insets = useMemo(\n () =>\n typeof hitSlop === 'number' ? numberAsInset(hitSlop) : hitSlop ?? {},\n [hitSlop]\n );\n\n const normalizedPressRetentionOffset: Insets = useMemo(\n () =>\n typeof pressRetentionOffset === 'number'\n ? numberAsInset(pressRetentionOffset)\n : pressRetentionOffset ?? {},\n [pressRetentionOffset]\n );\n\n const hoverInTimeout = useRef<number | null>(null);\n const hoverOutTimeout = useRef<number | null>(null);\n\n const hoverGesture = useMemo(\n () =>\n Gesture.Hover()\n .manualActivation(true) // Stops Hover from blocking Native gesture activation on web\n .cancelsTouchesInView(false)\n .onBegin((event) => {\n if (hoverOutTimeout.current) {\n clearTimeout(hoverOutTimeout.current);\n }\n if (delayHoverIn) {\n hoverInTimeout.current = setTimeout(\n () => onHoverIn?.(gestureToPressableEvent(event)),\n delayHoverIn\n );\n return;\n }\n onHoverIn?.(gestureToPressableEvent(event));\n })\n .onFinalize((event) => {\n if (hoverInTimeout.current) {\n clearTimeout(hoverInTimeout.current);\n }\n if (delayHoverOut) {\n hoverOutTimeout.current = setTimeout(\n () => onHoverOut?.(gestureToPressableEvent(event)),\n delayHoverOut\n );\n return;\n }\n onHoverOut?.(gestureToPressableEvent(event));\n }),\n [delayHoverIn, delayHoverOut, onHoverIn, onHoverOut]\n );\n\n const pressDelayTimeoutRef = useRef<number | null>(null);\n const isTouchPropagationAllowed = useRef<boolean>(false);\n\n // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use\n const deferredEventPayload = useRef<PressableEvent | null>(null);\n\n const pressInHandler = useCallback(\n (event: PressableEvent) => {\n if (handlingOnTouchesDown.current) {\n deferredEventPayload.current = event;\n }\n\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n deferredEventPayload.current = null;\n\n onPressIn?.(event);\n isPressCallbackEnabled.current = true;\n pressDelayTimeoutRef.current = null;\n setPressedState(true);\n },\n [onPressIn]\n );\n\n const pressOutHandler = useCallback(\n (event: PressableEvent) => {\n if (\n !hasPassedBoundsChecks.current ||\n event.nativeEvent.touches.length >\n event.nativeEvent.changedTouches.length\n ) {\n return;\n }\n\n if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {\n // When delay is preemptively finished by lifting touches,\n // we want to immediately activate it's effects - pressInHandler,\n // even though we are located at the pressOutHandler\n clearTimeout(pressDelayTimeoutRef.current);\n pressInHandler(event);\n }\n\n if (deferredEventPayload.current) {\n onPressIn?.(deferredEventPayload.current);\n deferredEventPayload.current = null;\n }\n\n onPressOut?.(event);\n\n if (isPressCallbackEnabled.current) {\n onPress?.(event);\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n\n isTouchPropagationAllowed.current = false;\n hasPassedBoundsChecks.current = false;\n isPressCallbackEnabled.current = true;\n setPressedState(false);\n },\n [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]\n );\n\n const handlingOnTouchesDown = useRef<boolean>(false);\n const onEndHandlingTouchesDown = useRef<(() => void) | null>(null);\n const cancelledMidPress = useRef<boolean>(false);\n\n const activateLongPress = useCallback(\n (event: GestureTouchEvent) => {\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n onLongPress?.(gestureTouchToPressableEvent(event));\n isPressCallbackEnabled.current = false;\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n },\n [onLongPress]\n );\n\n const longPressTimeoutRef = useRef<number | null>(null);\n const longPressMinDuration =\n (delayLongPress ?? DEFAULT_LONG_PRESS_DURATION) +\n (unstable_pressDelay ?? 0);\n\n const pressAndTouchGesture = useMemo(\n () =>\n Gesture.LongPress()\n .minDuration(INT32_MAX) // Stops long press from blocking native gesture\n .maxDistance(INT32_MAX) // Stops long press from cancelling after set distance\n .cancelsTouchesInView(false)\n .onTouchesDown((event) => {\n handlingOnTouchesDown.current = true;\n pressableRef.current?.measure((_x, _y, width, height) => {\n if (\n !isTouchWithinInset(\n {\n width,\n height,\n },\n normalizedHitSlop,\n event.changedTouches.at(-1)\n ) ||\n hasPassedBoundsChecks.current ||\n cancelledMidPress.current\n ) {\n cancelledMidPress.current = false;\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n return;\n }\n\n hasPassedBoundsChecks.current = true;\n\n // In case of multiple touches, the first one starts long press gesture\n if (longPressTimeoutRef.current === null) {\n // Start long press gesture timer\n longPressTimeoutRef.current = setTimeout(\n () => activateLongPress(event),\n longPressMinDuration\n );\n }\n\n if (unstable_pressDelay) {\n pressDelayTimeoutRef.current = setTimeout(() => {\n pressInHandler(gestureTouchToPressableEvent(event));\n }, unstable_pressDelay);\n } else {\n pressInHandler(gestureTouchToPressableEvent(event));\n }\n\n onEndHandlingTouchesDown.current?.();\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n });\n })\n .onTouchesUp((event) => {\n if (handlingOnTouchesDown.current) {\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n // On iOS, short taps will make LongPress gesture call onTouchesUp before Native gesture calls onStart\n // This variable ensures that onStart isn't detected as the first gesture since Pressable is pressed.\n if (deferredEventPayload.current !== null) {\n shouldPreventNativeEffects.current = true;\n }\n pressOutHandler(gestureTouchToPressableEvent(event));\n })\n .onTouchesCancelled((event) => {\n isPressCallbackEnabled.current = false;\n\n if (handlingOnTouchesDown.current) {\n cancelledMidPress.current = true;\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n\n if (\n !hasPassedBoundsChecks.current ||\n event.allTouches.length > event.changedTouches.length\n ) {\n return;\n }\n\n pressOutHandler(gestureTouchToPressableEvent(event));\n }),\n [\n activateLongPress,\n longPressMinDuration,\n normalizedHitSlop,\n pressInHandler,\n pressOutHandler,\n unstable_pressDelay,\n ]\n );\n\n // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events\n const buttonGesture = useMemo(\n () =>\n Gesture.Native()\n .onBegin(() => {\n // Android sets BEGAN state on press down\n if (Platform.OS === 'android') {\n isTouchPropagationAllowed.current = true;\n }\n })\n .onStart(() => {\n if (Platform.OS === 'web') {\n isTouchPropagationAllowed.current = true;\n }\n\n // iOS sets ACTIVE state on press down\n if (Platform.OS !== 'ios') {\n return;\n }\n\n if (deferredEventPayload.current) {\n isTouchPropagationAllowed.current = true;\n\n if (hasPassedBoundsChecks.current) {\n pressInHandler(deferredEventPayload.current);\n deferredEventPayload.current = null;\n } else {\n pressOutHandler(deferredEventPayload.current);\n isTouchPropagationAllowed.current = false;\n }\n\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n isTouchPropagationAllowed.current = true;\n return;\n }\n\n if (shouldPreventNativeEffects.current) {\n shouldPreventNativeEffects.current = false;\n return;\n }\n\n isTouchPropagationAllowed.current = true;\n }),\n [pressInHandler, pressOutHandler]\n );\n\n const appliedHitSlop = addInsets(\n normalizedHitSlop,\n normalizedPressRetentionOffset\n );\n\n const isPressableEnabled = disabled !== true;\n\n const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];\n\n for (const gesture of gestures) {\n gesture.enabled(isPressableEnabled);\n gesture.runOnJS(true);\n gesture.hitSlop(appliedHitSlop);\n gesture.shouldCancelWhenOutside(false);\n\n if (Platform.OS !== 'web') {\n gesture.shouldCancelWhenOutside(true);\n }\n }\n\n // Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area\n buttonGesture.hitSlop(normalizedHitSlop);\n\n const gesture = Gesture.Simultaneous(...gestures);\n\n const defaultRippleColor = android_ripple ? undefined : 'transparent';\n\n // `cursor: 'pointer'` on `RNButton` crashes iOS\n const pointerStyle: StyleProp<ViewStyle> =\n Platform.OS === 'web' ? { cursor: 'pointer' } : {};\n\n const styleProp =\n typeof style === 'function' ? style({ pressed: pressedState }) : style;\n\n const childrenProp =\n typeof children === 'function'\n ? children({ pressed: pressedState })\n : children;\n\n const flattenedStyles = StyleSheet.flatten(styleProp ?? {});\n\n const [innerStyles, outerStyles] = splitStyles(flattenedStyles);\n\n return (\n <View {...remainingProps} style={outerStyles}>\n <GestureDetector gesture={gesture}>\n <NativeButton\n ref={pressableRef}\n hitSlop={appliedHitSlop}\n enabled={isPressableEnabled}\n touchSoundDisabled={android_disableSound ?? undefined}\n rippleColor={processColor(\n android_ripple?.color ?? defaultRippleColor\n )}\n rippleRadius={android_ripple?.radius ?? undefined}\n style={[\n { width: '100%', height: '100%' },\n pointerStyle,\n innerStyles,\n ]}>\n {childrenProp}\n {__DEV__ ? (\n <PressabilityDebugView color=\"red\" hitSlop={normalizedHitSlop} />\n ) : null}\n </NativeButton>\n </GestureDetector>\n </View>\n );\n}\n"]}
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "PressableProps", {
7
- enumerable: true,
8
- get: function () {
9
- return _PressableProps.PressableProps;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "default", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -16,8 +10,6 @@ Object.defineProperty(exports, "default", {
16
10
  }
17
11
  });
18
12
 
19
- var _PressableProps = require("./PressableProps");
20
-
21
13
  var _Pressable = _interopRequireDefault(require("./Pressable"));
22
14
 
23
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { PressableProps } from './PressableProps';\nexport { default } from './Pressable';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA","sourcesContent":["export type { PressableProps } from './PressableProps';\nexport { default } from './Pressable';\n"]}
@@ -19,11 +19,29 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
19
19
 
20
20
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
- // Similarily to the DrawerLayout component this deserves to be put in a
23
- // separate repo. Although, keeping it here for the time being will allow us to
24
- // move faster and fix possible issues quicker
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
25
24
  const DRAG_TOSS = 0.05;
26
25
  const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props, ref) {
26
+ const {
27
+ leftThreshold,
28
+ rightThreshold,
29
+ onSwipeableOpenStartDrag,
30
+ onSwipeableCloseStartDrag,
31
+ enableTrackpadTwoFingerGesture,
32
+ enabled,
33
+ containerStyle,
34
+ childrenContainerStyle,
35
+ animationOptions,
36
+ overshootLeft,
37
+ overshootRight,
38
+ onSwipeableWillOpen,
39
+ onSwipeableWillClose,
40
+ onSwipeableOpen,
41
+ onSwipeableClose,
42
+ testID,
43
+ ...remainingProps
44
+ } = props;
27
45
  const rowState = (0, _reactNativeReanimated.useSharedValue)(0);
28
46
  const userDrag = (0, _reactNativeReanimated.useSharedValue)(0);
29
47
  const appliedTranslation = (0, _reactNativeReanimated.useSharedValue)(0);
@@ -57,8 +75,8 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
57
75
  friction = defaultProps.friction,
58
76
  overshootFriction = defaultProps.overshootFriction
59
77
  } = props;
60
- const overshootLeftProp = props.overshootLeft;
61
- const overshootRightProp = props.overshootRight;
78
+ const overshootLeftProp = overshootLeft;
79
+ const overshootRightProp = overshootRight;
62
80
  const calculateCurrentOffset = (0, _react.useCallback)(() => {
63
81
  'worklet';
64
82
 
@@ -87,31 +105,31 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
87
105
  };
88
106
 
89
107
  const dispatchImmediateEvents = (0, _react.useCallback)((fromValue, toValue) => {
90
- if (toValue > 0 && props.onSwipeableWillOpen) {
91
- props.onSwipeableWillOpen('left');
92
- } else if (toValue < 0 && props.onSwipeableWillOpen) {
93
- props.onSwipeableWillOpen('right');
94
- } else if (props.onSwipeableWillClose) {
108
+ if (toValue > 0 && onSwipeableWillOpen) {
109
+ onSwipeableWillOpen('left');
110
+ } else if (toValue < 0 && onSwipeableWillOpen) {
111
+ onSwipeableWillOpen('right');
112
+ } else if (onSwipeableWillClose) {
95
113
  const closingDirection = fromValue > 0 ? 'left' : 'right';
96
- props.onSwipeableWillClose(closingDirection);
114
+ onSwipeableWillClose(closingDirection);
97
115
  }
98
- }, [props, props.onSwipeableWillClose, props.onSwipeableWillOpen, swipeableMethods]);
116
+ }, [onSwipeableWillClose, onSwipeableWillOpen]);
99
117
  const dispatchEndEvents = (0, _react.useCallback)((fromValue, toValue) => {
100
- if (toValue > 0 && props.onSwipeableOpen) {
101
- props.onSwipeableOpen('left', swipeableMethods.current);
102
- } else if (toValue < 0 && props.onSwipeableOpen) {
103
- props.onSwipeableOpen('right', swipeableMethods.current);
104
- } else if (props.onSwipeableClose) {
118
+ if (toValue > 0 && onSwipeableOpen) {
119
+ onSwipeableOpen('left', swipeableMethods.current);
120
+ } else if (toValue < 0 && onSwipeableOpen) {
121
+ onSwipeableOpen('right', swipeableMethods.current);
122
+ } else if (onSwipeableClose) {
105
123
  const closingDirection = fromValue > 0 ? 'left' : 'right';
106
- props.onSwipeableClose(closingDirection, swipeableMethods.current);
124
+ onSwipeableClose(closingDirection, swipeableMethods.current);
107
125
  }
108
- }, [props, props.onSwipeableClose, props.onSwipeableOpen, swipeableMethods]);
109
- const animationOptionsProp = props.animationOptions;
126
+ }, [onSwipeableClose, onSwipeableOpen]);
127
+ const animationOptionsProp = animationOptions;
110
128
  const animateRow = (0, _react.useCallback)((fromValue, toValue, velocityX) => {
111
129
  'worklet';
112
130
 
113
131
  rowState.value = Math.sign(toValue);
114
- const springConfig = {
132
+ const translationSpringConfig = {
115
133
  duration: 1000,
116
134
  dampingRatio: 0.9,
117
135
  stiffness: 500,
@@ -119,18 +137,19 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
119
137
  overshootClamping: true,
120
138
  ...animationOptionsProp
121
139
  };
122
- appliedTranslation.value = (0, _reactNativeReanimated.withSpring)(toValue, springConfig, isFinished => {
140
+ const progressSpringConfig = { ...translationSpringConfig,
141
+ velocity: 0
142
+ };
143
+ appliedTranslation.value = (0, _reactNativeReanimated.withSpring)(toValue, translationSpringConfig, isFinished => {
123
144
  if (isFinished) {
124
145
  (0, _reactNativeReanimated.runOnJS)(dispatchEndEvents)(fromValue, toValue);
125
146
  }
126
147
  });
127
- const progressTarget = toValue === 0 ? 0 : 1; // Velocity is in px, while progress is in %
128
-
129
- springConfig.velocity = 0;
130
- showLeftProgress.value = leftWidth.value > 0 ? (0, _reactNativeReanimated.withSpring)(progressTarget, springConfig) : 0;
131
- showRightProgress.value = rightWidth.value > 0 ? (0, _reactNativeReanimated.withSpring)(progressTarget, springConfig) : 0;
148
+ const progressTarget = toValue === 0 ? 0 : 1;
149
+ showLeftProgress.value = leftWidth.value > 0 ? (0, _reactNativeReanimated.withSpring)(progressTarget, progressSpringConfig) : 0;
150
+ showRightProgress.value = rightWidth.value > 0 ? (0, _reactNativeReanimated.withSpring)(progressTarget, progressSpringConfig) : 0;
132
151
  (0, _reactNativeReanimated.runOnJS)(dispatchImmediateEvents)(fromValue, toValue);
133
- }, [showLeftProgress, appliedTranslation, dispatchEndEvents, dispatchImmediateEvents, animationOptionsProp, rowState]);
152
+ }, [rowState, animationOptionsProp, appliedTranslation, showLeftProgress, leftWidth.value, showRightProgress, rightWidth.value, dispatchImmediateEvents, dispatchEndEvents]);
134
153
 
135
154
  const onRowLayout = ({
136
155
  nativeEvent
@@ -203,8 +222,8 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
203
222
  }) => rightOffset.value = nativeEvent.layout.x
204
223
  }));
205
224
 
206
- const leftThresholdProp = props.leftThreshold;
207
- const rightThresholdProp = props.rightThreshold;
225
+ const leftThresholdProp = leftThreshold;
226
+ const rightThresholdProp = rightThreshold;
208
227
 
209
228
  const handleRelease = event => {
210
229
  'worklet';
@@ -253,9 +272,6 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
253
272
  }
254
273
  });
255
274
 
256
- const onSwipeableOpenStartDrag = props.onSwipeableOpenStartDrag;
257
- const onSwipeableCloseStartDrag = props.onSwipeableCloseStartDrag;
258
-
259
275
  const panGesture = _gestureObjects.GestureObjects.Pan().onUpdate(event => {
260
276
  userDrag.value = event.translationX;
261
277
  const direction = rowState.value === -1 ? 'right' : rowState.value === 1 ? 'left' : event.translationX > 0 ? 'left' : 'right';
@@ -271,34 +287,37 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
271
287
  handleRelease(event);
272
288
  });
273
289
 
274
- if (props.enableTrackpadTwoFingerGesture) {
275
- panGesture.enableTrackpadTwoFingerGesture(props.enableTrackpadTwoFingerGesture);
290
+ if (enableTrackpadTwoFingerGesture) {
291
+ panGesture.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture);
276
292
  }
277
293
 
278
294
  panGesture.activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge]);
279
295
  tapGesture.shouldCancelWhenOutside(true);
280
296
  (0, _react.useImperativeHandle)(ref, () => swipeableMethods.current, [swipeableMethods]);
281
- panGesture.enabled(props.enabled !== false);
297
+ panGesture.enabled(enabled !== false);
282
298
  const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
283
299
  transform: [{
284
300
  translateX: appliedTranslation.value
285
301
  }],
286
302
  pointerEvents: rowState.value === 0 ? 'auto' : 'box-only'
287
303
  }), [appliedTranslation, rowState]);
288
- const containerStyle = props.containerStyle;
289
- const childrenContainerStyle = props.childrenContainerStyle;
290
- return /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
304
+
305
+ const swipeableComponent = /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
291
306
  gesture: panGesture,
292
307
  touchAction: "pan-y"
293
- }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
308
+ }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({}, remainingProps, {
294
309
  onLayout: onRowLayout,
295
310
  style: [styles.container, containerStyle]
296
- }, leftElement, rightElement, /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
311
+ }), leftElement, rightElement, /*#__PURE__*/_react.default.createElement(_GestureDetector.GestureDetector, {
297
312
  gesture: tapGesture,
298
313
  touchAction: "pan-y"
299
314
  }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
300
315
  style: [animatedStyle, childrenContainerStyle]
301
316
  }, children))));
317
+
318
+ return testID ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
319
+ testID: testID
320
+ }, swipeableComponent) : swipeableComponent;
302
321
  });
303
322
  var _default = Swipeable;
304
323
  exports.default = _default;