react-native-gesture-handler 2.18.1 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/android/build.gradle +4 -17
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +5 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
- package/apple/Handlers/RNFlingHandler.h +1 -0
- package/apple/Handlers/RNFlingHandler.m +153 -19
- package/apple/Handlers/RNHoverHandler.m +44 -2
- package/apple/Handlers/RNLongPressHandler.m +109 -20
- package/apple/Handlers/RNManualHandler.m +53 -29
- package/apple/Handlers/RNNativeViewHandler.mm +22 -15
- package/apple/RNGHUIKit.h +2 -0
- package/apple/RNGHVector.h +31 -0
- package/apple/RNGHVector.m +67 -0
- package/apple/RNGestureHandler.h +7 -0
- package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
- package/apple/RNGestureHandlerButtonComponentView.mm +6 -0
- package/apple/RNGestureHandlerDirection.h +25 -0
- package/lib/commonjs/PointerType.js +2 -1
- package/lib/commonjs/PointerType.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +67 -70
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable/index.js +0 -8
- package/lib/commonjs/components/Pressable/index.js.map +1 -1
- package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
- package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
- package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/commonjs/mocks.js +16 -3
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/utils.js +4 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/constants.js +3 -3
- package/lib/commonjs/web/constants.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -8
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
- package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/commonjs/web/tools/Vector.js +4 -2
- package/lib/commonjs/web/tools/Vector.js.map +1 -1
- package/lib/commonjs/web/utils.js +14 -13
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/module/PointerType.js +2 -1
- package/lib/module/PointerType.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +66 -70
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/Pressable/index.js +0 -1
- package/lib/module/components/Pressable/index.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable.js +58 -37
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
- package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/module/handlers/gestures/longPressGesture.js +10 -0
- package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/module/mocks.js +13 -3
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/utils.js +1 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/constants.js +1 -1
- package/lib/module/web/constants.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +1 -0
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +4 -0
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -8
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/KeyboardEventManager.js +96 -0
- package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/module/web/tools/Vector.js +5 -3
- package/lib/module/web/tools/Vector.js.map +1 -1
- package/lib/module/web/utils.js +14 -13
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/PointerType.d.ts +2 -1
- package/lib/typescript/components/Pressable/index.d.ts +1 -1
- package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
- package/lib/typescript/mocks.d.ts +4 -3
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/web/constants.d.ts +1 -1
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/interfaces.d.ts +1 -1
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
- package/package.json +3 -3
- package/src/PointerType.ts +1 -0
- package/src/components/Pressable/Pressable.tsx +70 -50
- package/src/components/Pressable/index.ts +1 -1
- package/src/components/ReanimatedSwipeable.tsx +70 -47
- package/src/handlers/LongPressGestureHandler.ts +6 -0
- package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
- package/src/handlers/gestures/longPressGesture.ts +9 -0
- package/src/{mocks.ts → mocks.tsx} +8 -3
- package/src/utils.ts +2 -0
- package/src/web/constants.ts +1 -1
- package/src/web/handlers/GestureHandler.ts +3 -1
- package/src/web/handlers/LongPressGestureHandler.ts +49 -10
- package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
- package/src/web/handlers/PanGestureHandler.ts +4 -0
- package/src/web/interfaces.ts +1 -1
- package/src/web/tools/GestureHandlerDelegate.ts +1 -0
- package/src/web/tools/GestureHandlerWebDelegate.ts +67 -8
- package/src/web/tools/KeyboardEventManager.ts +91 -0
- package/src/web/tools/Vector.ts +4 -3
- package/src/web/utils.ts +15 -13
@@ -1,3 +1,5 @@
|
|
1
|
+
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); }
|
2
|
+
|
1
3
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
2
4
|
import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';
|
3
5
|
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
|
@@ -5,71 +7,71 @@ import { Platform, View, processColor, StyleSheet } from 'react-native';
|
|
5
7
|
import NativeButton from '../GestureHandlerButton';
|
6
8
|
import { numberAsInset, gestureToPressableEvent, isTouchWithinInset, gestureTouchToPressableEvent, addInsets, splitStyles } from './utils';
|
7
9
|
import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
|
10
|
+
import { INT32_MAX } from '../../utils';
|
8
11
|
const DEFAULT_LONG_PRESS_DURATION = 500;
|
9
12
|
export default function Pressable(props) {
|
10
|
-
var
|
11
|
-
|
12
|
-
const
|
13
|
+
var _android_ripple$color, _android_ripple$radiu;
|
14
|
+
|
15
|
+
const {
|
16
|
+
testOnly_pressed,
|
17
|
+
hitSlop,
|
18
|
+
pressRetentionOffset,
|
19
|
+
delayHoverIn,
|
20
|
+
onHoverIn,
|
21
|
+
delayHoverOut,
|
22
|
+
onHoverOut,
|
23
|
+
delayLongPress,
|
24
|
+
unstable_pressDelay,
|
25
|
+
onPress,
|
26
|
+
onPressIn,
|
27
|
+
onPressOut,
|
28
|
+
onLongPress,
|
29
|
+
style,
|
30
|
+
children,
|
31
|
+
android_disableSound,
|
32
|
+
android_ripple,
|
33
|
+
disabled,
|
34
|
+
...remainingProps
|
35
|
+
} = props;
|
36
|
+
const [pressedState, setPressedState] = useState(testOnly_pressed !== null && testOnly_pressed !== void 0 ? testOnly_pressed : false);
|
13
37
|
const pressableRef = useRef(null); // Disabled when onLongPress has been called
|
14
38
|
|
15
39
|
const isPressCallbackEnabled = useRef(true);
|
16
40
|
const hasPassedBoundsChecks = useRef(false);
|
17
41
|
const shouldPreventNativeEffects = useRef(false);
|
18
|
-
const normalizedHitSlop = useMemo(() => {
|
19
|
-
|
20
|
-
|
21
|
-
return typeof props.hitSlop === 'number' ? numberAsInset(props.hitSlop) : (_props$hitSlop = props.hitSlop) !== null && _props$hitSlop !== void 0 ? _props$hitSlop : {};
|
22
|
-
}, [props.hitSlop]);
|
23
|
-
const normalizedPressRetentionOffset = useMemo(() => {
|
24
|
-
var _props$pressRetention;
|
25
|
-
|
26
|
-
return typeof props.pressRetentionOffset === 'number' ? numberAsInset(props.pressRetentionOffset) : (_props$pressRetention = props.pressRetentionOffset) !== null && _props$pressRetention !== void 0 ? _props$pressRetention : {};
|
27
|
-
}, [props.pressRetentionOffset]);
|
42
|
+
const normalizedHitSlop = useMemo(() => typeof hitSlop === 'number' ? numberAsInset(hitSlop) : hitSlop !== null && hitSlop !== void 0 ? hitSlop : {}, [hitSlop]);
|
43
|
+
const normalizedPressRetentionOffset = useMemo(() => typeof pressRetentionOffset === 'number' ? numberAsInset(pressRetentionOffset) : pressRetentionOffset !== null && pressRetentionOffset !== void 0 ? pressRetentionOffset : {}, [pressRetentionOffset]);
|
28
44
|
const hoverInTimeout = useRef(null);
|
29
45
|
const hoverOutTimeout = useRef(null);
|
30
46
|
const hoverGesture = useMemo(() => Gesture.Hover().manualActivation(true) // Stops Hover from blocking Native gesture activation on web
|
31
47
|
.cancelsTouchesInView(false).onBegin(event => {
|
32
|
-
var _props$onHoverIn2;
|
33
|
-
|
34
48
|
if (hoverOutTimeout.current) {
|
35
49
|
clearTimeout(hoverOutTimeout.current);
|
36
50
|
}
|
37
51
|
|
38
|
-
if (
|
39
|
-
hoverInTimeout.current = setTimeout(() =>
|
40
|
-
var _props$onHoverIn;
|
41
|
-
|
42
|
-
return (_props$onHoverIn = props.onHoverIn) === null || _props$onHoverIn === void 0 ? void 0 : _props$onHoverIn.call(props, gestureToPressableEvent(event));
|
43
|
-
}, props.delayHoverIn);
|
52
|
+
if (delayHoverIn) {
|
53
|
+
hoverInTimeout.current = setTimeout(() => onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn(gestureToPressableEvent(event)), delayHoverIn);
|
44
54
|
return;
|
45
55
|
}
|
46
56
|
|
47
|
-
|
57
|
+
onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn(gestureToPressableEvent(event));
|
48
58
|
}).onFinalize(event => {
|
49
|
-
var _props$onHoverOut2;
|
50
|
-
|
51
59
|
if (hoverInTimeout.current) {
|
52
60
|
clearTimeout(hoverInTimeout.current);
|
53
61
|
}
|
54
62
|
|
55
|
-
if (
|
56
|
-
hoverOutTimeout.current = setTimeout(() =>
|
57
|
-
var _props$onHoverOut;
|
58
|
-
|
59
|
-
return (_props$onHoverOut = props.onHoverOut) === null || _props$onHoverOut === void 0 ? void 0 : _props$onHoverOut.call(props, gestureToPressableEvent(event));
|
60
|
-
}, props.delayHoverOut);
|
63
|
+
if (delayHoverOut) {
|
64
|
+
hoverOutTimeout.current = setTimeout(() => onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut(gestureToPressableEvent(event)), delayHoverOut);
|
61
65
|
return;
|
62
66
|
}
|
63
67
|
|
64
|
-
|
65
|
-
}), [
|
68
|
+
onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut(gestureToPressableEvent(event));
|
69
|
+
}), [delayHoverIn, delayHoverOut, onHoverIn, onHoverOut]);
|
66
70
|
const pressDelayTimeoutRef = useRef(null);
|
67
71
|
const isTouchPropagationAllowed = useRef(false); // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use
|
68
72
|
|
69
73
|
const deferredEventPayload = useRef(null);
|
70
74
|
const pressInHandler = useCallback(event => {
|
71
|
-
var _props$onPressIn;
|
72
|
-
|
73
75
|
if (handlingOnTouchesDown.current) {
|
74
76
|
deferredEventPayload.current = event;
|
75
77
|
}
|
@@ -79,19 +81,17 @@ export default function Pressable(props) {
|
|
79
81
|
}
|
80
82
|
|
81
83
|
deferredEventPayload.current = null;
|
82
|
-
|
84
|
+
onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(event);
|
83
85
|
isPressCallbackEnabled.current = true;
|
84
86
|
pressDelayTimeoutRef.current = null;
|
85
87
|
setPressedState(true);
|
86
|
-
}, [
|
88
|
+
}, [onPressIn]);
|
87
89
|
const pressOutHandler = useCallback(event => {
|
88
|
-
var _props$onPressOut;
|
89
|
-
|
90
90
|
if (!hasPassedBoundsChecks.current || event.nativeEvent.touches.length > event.nativeEvent.changedTouches.length) {
|
91
91
|
return;
|
92
92
|
}
|
93
93
|
|
94
|
-
if (
|
94
|
+
if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
|
95
95
|
// When delay is preemptively finished by lifting touches,
|
96
96
|
// we want to immediately activate it's effects - pressInHandler,
|
97
97
|
// even though we are located at the pressOutHandler
|
@@ -100,18 +100,14 @@ export default function Pressable(props) {
|
|
100
100
|
}
|
101
101
|
|
102
102
|
if (deferredEventPayload.current) {
|
103
|
-
|
104
|
-
|
105
|
-
(_props$onPressIn2 = props.onPressIn) === null || _props$onPressIn2 === void 0 ? void 0 : _props$onPressIn2.call(props, deferredEventPayload.current);
|
103
|
+
onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(deferredEventPayload.current);
|
106
104
|
deferredEventPayload.current = null;
|
107
105
|
}
|
108
106
|
|
109
|
-
|
107
|
+
onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
|
110
108
|
|
111
109
|
if (isPressCallbackEnabled.current) {
|
112
|
-
|
113
|
-
|
114
|
-
(_props$onPress = props.onPress) === null || _props$onPress === void 0 ? void 0 : _props$onPress.call(props, event);
|
110
|
+
onPress === null || onPress === void 0 ? void 0 : onPress(event);
|
115
111
|
}
|
116
112
|
|
117
113
|
if (longPressTimeoutRef.current) {
|
@@ -123,7 +119,7 @@ export default function Pressable(props) {
|
|
123
119
|
hasPassedBoundsChecks.current = false;
|
124
120
|
isPressCallbackEnabled.current = true;
|
125
121
|
setPressedState(false);
|
126
|
-
}, [pressInHandler,
|
122
|
+
}, [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]);
|
127
123
|
const handlingOnTouchesDown = useRef(false);
|
128
124
|
const onEndHandlingTouchesDown = useRef(null);
|
129
125
|
const cancelledMidPress = useRef(false);
|
@@ -133,9 +129,7 @@ export default function Pressable(props) {
|
|
133
129
|
}
|
134
130
|
|
135
131
|
if (hasPassedBoundsChecks.current) {
|
136
|
-
|
137
|
-
|
138
|
-
(_props$onLongPress = props.onLongPress) === null || _props$onLongPress === void 0 ? void 0 : _props$onLongPress.call(props, gestureTouchToPressableEvent(event));
|
132
|
+
onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress(gestureTouchToPressableEvent(event));
|
139
133
|
isPressCallbackEnabled.current = false;
|
140
134
|
}
|
141
135
|
|
@@ -143,11 +137,11 @@ export default function Pressable(props) {
|
|
143
137
|
clearTimeout(longPressTimeoutRef.current);
|
144
138
|
longPressTimeoutRef.current = null;
|
145
139
|
}
|
146
|
-
}, [
|
140
|
+
}, [onLongPress]);
|
147
141
|
const longPressTimeoutRef = useRef(null);
|
148
|
-
const longPressMinDuration = (
|
149
|
-
const pressAndTouchGesture = useMemo(() => Gesture.LongPress().minDuration(
|
150
|
-
.maxDistance(
|
142
|
+
const longPressMinDuration = (delayLongPress !== null && delayLongPress !== void 0 ? delayLongPress : DEFAULT_LONG_PRESS_DURATION) + (unstable_pressDelay !== null && unstable_pressDelay !== void 0 ? unstable_pressDelay : 0);
|
143
|
+
const pressAndTouchGesture = useMemo(() => Gesture.LongPress().minDuration(INT32_MAX) // Stops long press from blocking native gesture
|
144
|
+
.maxDistance(INT32_MAX) // Stops long press from cancelling after set distance
|
151
145
|
.cancelsTouchesInView(false).onTouchesDown(event => {
|
152
146
|
var _pressableRef$current;
|
153
147
|
|
@@ -172,10 +166,10 @@ export default function Pressable(props) {
|
|
172
166
|
longPressTimeoutRef.current = setTimeout(() => activateLongPress(event), longPressMinDuration);
|
173
167
|
}
|
174
168
|
|
175
|
-
if (
|
169
|
+
if (unstable_pressDelay) {
|
176
170
|
pressDelayTimeoutRef.current = setTimeout(() => {
|
177
171
|
pressInHandler(gestureTouchToPressableEvent(event));
|
178
|
-
},
|
172
|
+
}, unstable_pressDelay);
|
179
173
|
} else {
|
180
174
|
pressInHandler(gestureTouchToPressableEvent(event));
|
181
175
|
}
|
@@ -214,7 +208,7 @@ export default function Pressable(props) {
|
|
214
208
|
}
|
215
209
|
|
216
210
|
pressOutHandler(gestureTouchToPressableEvent(event));
|
217
|
-
}), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler,
|
211
|
+
}), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler, unstable_pressDelay]); // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events
|
218
212
|
|
219
213
|
const buttonGesture = useMemo(() => Gesture.Native().onBegin(() => {
|
220
214
|
// Android sets BEGAN state on press down
|
@@ -258,7 +252,7 @@ export default function Pressable(props) {
|
|
258
252
|
isTouchPropagationAllowed.current = true;
|
259
253
|
}), [pressInHandler, pressOutHandler]);
|
260
254
|
const appliedHitSlop = addInsets(normalizedHitSlop, normalizedPressRetentionOffset);
|
261
|
-
const isPressableEnabled =
|
255
|
+
const isPressableEnabled = disabled !== true;
|
262
256
|
const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];
|
263
257
|
|
264
258
|
for (const gesture of gestures) {
|
@@ -275,32 +269,34 @@ export default function Pressable(props) {
|
|
275
269
|
|
276
270
|
buttonGesture.hitSlop(normalizedHitSlop);
|
277
271
|
const gesture = Gesture.Simultaneous(...gestures);
|
278
|
-
const defaultRippleColor =
|
272
|
+
const defaultRippleColor = android_ripple ? undefined : 'transparent'; // `cursor: 'pointer'` on `RNButton` crashes iOS
|
279
273
|
|
280
274
|
const pointerStyle = Platform.OS === 'web' ? {
|
281
275
|
cursor: 'pointer'
|
282
276
|
} : {};
|
283
|
-
const styleProp = typeof
|
277
|
+
const styleProp = typeof style === 'function' ? style({
|
284
278
|
pressed: pressedState
|
285
|
-
}) :
|
286
|
-
const childrenProp = typeof
|
279
|
+
}) : style;
|
280
|
+
const childrenProp = typeof children === 'function' ? children({
|
287
281
|
pressed: pressedState
|
288
|
-
}) :
|
282
|
+
}) : children;
|
289
283
|
const flattenedStyles = StyleSheet.flatten(styleProp !== null && styleProp !== void 0 ? styleProp : {});
|
290
284
|
const [innerStyles, outerStyles] = splitStyles(flattenedStyles);
|
291
|
-
return /*#__PURE__*/React.createElement(View, {
|
285
|
+
return /*#__PURE__*/React.createElement(View, _extends({}, remainingProps, {
|
292
286
|
style: outerStyles
|
293
|
-
}, /*#__PURE__*/React.createElement(GestureDetector, {
|
287
|
+
}), /*#__PURE__*/React.createElement(GestureDetector, {
|
294
288
|
gesture: gesture
|
295
289
|
}, /*#__PURE__*/React.createElement(NativeButton, {
|
296
290
|
ref: pressableRef,
|
297
|
-
testID: props.testID,
|
298
291
|
hitSlop: appliedHitSlop,
|
299
292
|
enabled: isPressableEnabled,
|
300
|
-
touchSoundDisabled:
|
301
|
-
rippleColor: processColor((
|
302
|
-
rippleRadius: (
|
303
|
-
style: [
|
293
|
+
touchSoundDisabled: android_disableSound !== null && android_disableSound !== void 0 ? android_disableSound : undefined,
|
294
|
+
rippleColor: 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),
|
295
|
+
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,
|
296
|
+
style: [{
|
297
|
+
width: '100%',
|
298
|
+
height: '100%'
|
299
|
+
}, pointerStyle, innerStyles]
|
304
300
|
}, childrenProp, __DEV__ ? /*#__PURE__*/React.createElement(PressabilityDebugView, {
|
305
301
|
color: "red",
|
306
302
|
hitSlop: normalizedHitSlop
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Pressable.tsx"],"names":["React","useCallback","useMemo","useRef","useState","GestureObjects","Gesture","GestureDetector","Platform","View","processColor","StyleSheet","NativeButton","numberAsInset","gestureToPressableEvent","isTouchWithinInset","gestureTouchToPressableEvent","addInsets","splitStyles","PressabilityDebugView","DEFAULT_LONG_PRESS_DURATION","Pressable","props","pressedState","setPressedState","testOnly_pressed","pressableRef","isPressCallbackEnabled","hasPassedBoundsChecks","shouldPreventNativeEffects","normalizedHitSlop","hitSlop","normalizedPressRetentionOffset","pressRetentionOffset","hoverInTimeout","hoverOutTimeout","hoverGesture","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","OS","onStart","appliedHitSlop","isPressableEnabled","disabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","android_ripple","undefined","pointerStyle","cursor","styleProp","style","pressed","childrenProp","children","flattenedStyles","flatten","innerStyles","outerStyles","testID","android_disableSound","color","radius","absoluteFill","__DEV__"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,SAASC,cAAc,IAAIC,OAA3B,QAA0C,wCAA1C;AACA,SAASC,eAAT,QAAgC,yCAAhC;AAEA,SAEEC,QAFF,EAIEC,IAJF,EAMEC,YANF,EAOEC,UAPF,QAQO,cARP;AASA,OAAOC,YAAP,MAAyB,yBAAzB;AACA,SACEC,aADF,EAEEC,uBAFF,EAGEC,kBAHF,EAIEC,4BAJF,EAKEC,SALF,EAMEC,WANF,QAOO,SAPP;AAQA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","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":["React","useCallback","useMemo","useRef","useState","GestureObjects","Gesture","GestureDetector","Platform","View","processColor","StyleSheet","NativeButton","numberAsInset","gestureToPressableEvent","isTouchWithinInset","gestureTouchToPressableEvent","addInsets","splitStyles","PressabilityDebugView","INT32_MAX","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","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","maxDistance","onTouchesDown","measure","_x","_y","width","height","at","onTouchesUp","onTouchesCancelled","allTouches","buttonGesture","Native","OS","onStart","appliedHitSlop","isPressableEnabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","undefined","pointerStyle","cursor","styleProp","pressed","childrenProp","flattenedStyles","flatten","innerStyles","outerStyles","color","radius","__DEV__"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,SAASC,cAAc,IAAIC,OAA3B,QAA0C,wCAA1C;AACA,SAASC,eAAT,QAAgC,yCAAhC;AAEA,SAEEC,QAFF,EAIEC,IAJF,EAMEC,YANF,EAOEC,UAPF,QAQO,cARP;AASA,OAAOC,YAAP,MAAyB,yBAAzB;AACA,SACEC,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EA,cAAc,CAAE4E,MAAlB,yEAA4BX,SAR1C;AASE,IAAA,KAAK,EAAE,CACL;AAAEnB,MAAAA,KAAK,EAAE,MAAT;AAAiBC,MAAAA,MAAM,EAAE;AAAzB,KADK,EAELmB,YAFK,EAGLO,WAHK;AATT,KAcGH,YAdH,EAeGO,OAAO,gBACN,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAC,KAA7B;AAAmC,IAAA,OAAO,EAAEpE;AAA5C,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"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["default"],"mappings":"AACA,SAASA,OAAT,QAAwB,aAAxB","sourcesContent":["export type { PressableProps } from './PressableProps';\nexport { default } from './Pressable';\n"]}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
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); }
|
2
|
+
|
1
3
|
// Similarily to the DrawerLayout component this deserves to be put in a
|
2
4
|
// separate repo. Although, keeping it here for the time being will allow us to
|
3
5
|
// move faster and fix possible issues quicker
|
@@ -8,6 +10,25 @@ import Animated, { Extrapolation, interpolate, runOnJS, useAnimatedStyle, useSha
|
|
8
10
|
import { I18nManager, StyleSheet, View } from 'react-native';
|
9
11
|
const DRAG_TOSS = 0.05;
|
10
12
|
const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
13
|
+
const {
|
14
|
+
leftThreshold,
|
15
|
+
rightThreshold,
|
16
|
+
onSwipeableOpenStartDrag,
|
17
|
+
onSwipeableCloseStartDrag,
|
18
|
+
enableTrackpadTwoFingerGesture,
|
19
|
+
enabled,
|
20
|
+
containerStyle,
|
21
|
+
childrenContainerStyle,
|
22
|
+
animationOptions,
|
23
|
+
overshootLeft,
|
24
|
+
overshootRight,
|
25
|
+
onSwipeableWillOpen,
|
26
|
+
onSwipeableWillClose,
|
27
|
+
onSwipeableOpen,
|
28
|
+
onSwipeableClose,
|
29
|
+
testID,
|
30
|
+
...remainingProps
|
31
|
+
} = props;
|
11
32
|
const rowState = useSharedValue(0);
|
12
33
|
const userDrag = useSharedValue(0);
|
13
34
|
const appliedTranslation = useSharedValue(0);
|
@@ -41,8 +62,8 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
41
62
|
friction = defaultProps.friction,
|
42
63
|
overshootFriction = defaultProps.overshootFriction
|
43
64
|
} = props;
|
44
|
-
const overshootLeftProp =
|
45
|
-
const overshootRightProp =
|
65
|
+
const overshootLeftProp = overshootLeft;
|
66
|
+
const overshootRightProp = overshootRight;
|
46
67
|
const calculateCurrentOffset = useCallback(() => {
|
47
68
|
'worklet';
|
48
69
|
|
@@ -71,31 +92,31 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
71
92
|
};
|
72
93
|
|
73
94
|
const dispatchImmediateEvents = useCallback((fromValue, toValue) => {
|
74
|
-
if (toValue > 0 &&
|
75
|
-
|
76
|
-
} else if (toValue < 0 &&
|
77
|
-
|
78
|
-
} else if (
|
95
|
+
if (toValue > 0 && onSwipeableWillOpen) {
|
96
|
+
onSwipeableWillOpen('left');
|
97
|
+
} else if (toValue < 0 && onSwipeableWillOpen) {
|
98
|
+
onSwipeableWillOpen('right');
|
99
|
+
} else if (onSwipeableWillClose) {
|
79
100
|
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
80
|
-
|
101
|
+
onSwipeableWillClose(closingDirection);
|
81
102
|
}
|
82
|
-
}, [
|
103
|
+
}, [onSwipeableWillClose, onSwipeableWillOpen]);
|
83
104
|
const dispatchEndEvents = useCallback((fromValue, toValue) => {
|
84
|
-
if (toValue > 0 &&
|
85
|
-
|
86
|
-
} else if (toValue < 0 &&
|
87
|
-
|
88
|
-
} else if (
|
105
|
+
if (toValue > 0 && onSwipeableOpen) {
|
106
|
+
onSwipeableOpen('left', swipeableMethods.current);
|
107
|
+
} else if (toValue < 0 && onSwipeableOpen) {
|
108
|
+
onSwipeableOpen('right', swipeableMethods.current);
|
109
|
+
} else if (onSwipeableClose) {
|
89
110
|
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
90
|
-
|
111
|
+
onSwipeableClose(closingDirection, swipeableMethods.current);
|
91
112
|
}
|
92
|
-
}, [
|
93
|
-
const animationOptionsProp =
|
113
|
+
}, [onSwipeableClose, onSwipeableOpen]);
|
114
|
+
const animationOptionsProp = animationOptions;
|
94
115
|
const animateRow = useCallback((fromValue, toValue, velocityX) => {
|
95
116
|
'worklet';
|
96
117
|
|
97
118
|
rowState.value = Math.sign(toValue);
|
98
|
-
const
|
119
|
+
const translationSpringConfig = {
|
99
120
|
duration: 1000,
|
100
121
|
dampingRatio: 0.9,
|
101
122
|
stiffness: 500,
|
@@ -103,18 +124,19 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
103
124
|
overshootClamping: true,
|
104
125
|
...animationOptionsProp
|
105
126
|
};
|
106
|
-
|
127
|
+
const progressSpringConfig = { ...translationSpringConfig,
|
128
|
+
velocity: 0
|
129
|
+
};
|
130
|
+
appliedTranslation.value = withSpring(toValue, translationSpringConfig, isFinished => {
|
107
131
|
if (isFinished) {
|
108
132
|
runOnJS(dispatchEndEvents)(fromValue, toValue);
|
109
133
|
}
|
110
134
|
});
|
111
|
-
const progressTarget = toValue === 0 ? 0 : 1;
|
112
|
-
|
113
|
-
|
114
|
-
showLeftProgress.value = leftWidth.value > 0 ? withSpring(progressTarget, springConfig) : 0;
|
115
|
-
showRightProgress.value = rightWidth.value > 0 ? withSpring(progressTarget, springConfig) : 0;
|
135
|
+
const progressTarget = toValue === 0 ? 0 : 1;
|
136
|
+
showLeftProgress.value = leftWidth.value > 0 ? withSpring(progressTarget, progressSpringConfig) : 0;
|
137
|
+
showRightProgress.value = rightWidth.value > 0 ? withSpring(progressTarget, progressSpringConfig) : 0;
|
116
138
|
runOnJS(dispatchImmediateEvents)(fromValue, toValue);
|
117
|
-
}, [
|
139
|
+
}, [rowState, animationOptionsProp, appliedTranslation, showLeftProgress, leftWidth.value, showRightProgress, rightWidth.value, dispatchImmediateEvents, dispatchEndEvents]);
|
118
140
|
|
119
141
|
const onRowLayout = ({
|
120
142
|
nativeEvent
|
@@ -183,8 +205,8 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
183
205
|
nativeEvent
|
184
206
|
}) => rightOffset.value = nativeEvent.layout.x
|
185
207
|
}));
|
186
|
-
const leftThresholdProp =
|
187
|
-
const rightThresholdProp =
|
208
|
+
const leftThresholdProp = leftThreshold;
|
209
|
+
const rightThresholdProp = rightThreshold;
|
188
210
|
|
189
211
|
const handleRelease = event => {
|
190
212
|
'worklet';
|
@@ -232,8 +254,6 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
232
254
|
close();
|
233
255
|
}
|
234
256
|
});
|
235
|
-
const onSwipeableOpenStartDrag = props.onSwipeableOpenStartDrag;
|
236
|
-
const onSwipeableCloseStartDrag = props.onSwipeableCloseStartDrag;
|
237
257
|
const panGesture = Gesture.Pan().onUpdate(event => {
|
238
258
|
userDrag.value = event.translationX;
|
239
259
|
const direction = rowState.value === -1 ? 'right' : rowState.value === 1 ? 'left' : event.translationX > 0 ? 'left' : 'right';
|
@@ -249,34 +269,35 @@ const Swipeable = /*#__PURE__*/forwardRef(function Swipeable(props, ref) {
|
|
249
269
|
handleRelease(event);
|
250
270
|
});
|
251
271
|
|
252
|
-
if (
|
253
|
-
panGesture.enableTrackpadTwoFingerGesture(
|
272
|
+
if (enableTrackpadTwoFingerGesture) {
|
273
|
+
panGesture.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture);
|
254
274
|
}
|
255
275
|
|
256
276
|
panGesture.activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge]);
|
257
277
|
tapGesture.shouldCancelWhenOutside(true);
|
258
278
|
useImperativeHandle(ref, () => swipeableMethods.current, [swipeableMethods]);
|
259
|
-
panGesture.enabled(
|
279
|
+
panGesture.enabled(enabled !== false);
|
260
280
|
const animatedStyle = useAnimatedStyle(() => ({
|
261
281
|
transform: [{
|
262
282
|
translateX: appliedTranslation.value
|
263
283
|
}],
|
264
284
|
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only'
|
265
285
|
}), [appliedTranslation, rowState]);
|
266
|
-
const
|
267
|
-
const childrenContainerStyle = props.childrenContainerStyle;
|
268
|
-
return /*#__PURE__*/React.createElement(GestureDetector, {
|
286
|
+
const swipeableComponent = /*#__PURE__*/React.createElement(GestureDetector, {
|
269
287
|
gesture: panGesture,
|
270
288
|
touchAction: "pan-y"
|
271
|
-
}, /*#__PURE__*/React.createElement(Animated.View, {
|
289
|
+
}, /*#__PURE__*/React.createElement(Animated.View, _extends({}, remainingProps, {
|
272
290
|
onLayout: onRowLayout,
|
273
291
|
style: [styles.container, containerStyle]
|
274
|
-
}, leftElement, rightElement, /*#__PURE__*/React.createElement(GestureDetector, {
|
292
|
+
}), leftElement, rightElement, /*#__PURE__*/React.createElement(GestureDetector, {
|
275
293
|
gesture: tapGesture,
|
276
294
|
touchAction: "pan-y"
|
277
295
|
}, /*#__PURE__*/React.createElement(Animated.View, {
|
278
296
|
style: [animatedStyle, childrenContainerStyle]
|
279
297
|
}, children))));
|
298
|
+
return testID ? /*#__PURE__*/React.createElement(View, {
|
299
|
+
testID: testID
|
300
|
+
}, swipeableComponent) : swipeableComponent;
|
280
301
|
});
|
281
302
|
export default Swipeable;
|
282
303
|
const styles = StyleSheet.create({
|