react-native-gesture-handler 2.22.0 → 2.22.1
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.
- package/lib/commonjs/components/ReanimatedSwipeable.js +80 -47
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/handlers/createNativeWrapper.js +17 -6
- package/lib/commonjs/handlers/createNativeWrapper.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable.js +81 -48
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/handlers/createNativeWrapper.js +17 -6
- package/lib/module/handlers/createNativeWrapper.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ReanimatedSwipeable.tsx +101 -51
- package/src/handlers/createNativeWrapper.tsx +10 -4
@@ -67,20 +67,9 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
67
67
|
const appliedTranslation = (0, _reactNativeReanimated.useSharedValue)(0);
|
68
68
|
const rowWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
69
69
|
const leftWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
70
|
-
const rightWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
71
|
-
|
72
|
-
const rightOffset = (0, _reactNativeReanimated.useSharedValue)(null);
|
70
|
+
const rightWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
73
71
|
const showLeftProgress = (0, _reactNativeReanimated.useSharedValue)(0);
|
74
72
|
const showRightProgress = (0, _reactNativeReanimated.useSharedValue)(0);
|
75
|
-
const updateRightElementWidth = (0, _react.useCallback)(() => {
|
76
|
-
'worklet';
|
77
|
-
|
78
|
-
if (rightOffset.value === null) {
|
79
|
-
rightOffset.value = rowWidth.value;
|
80
|
-
}
|
81
|
-
|
82
|
-
rightWidth.value = Math.max(0, rowWidth.value - rightOffset.value);
|
83
|
-
}, [rightOffset, rightWidth, rowWidth]);
|
84
73
|
const updateAnimatedEvent = (0, _react.useCallback)(() => {
|
85
74
|
'worklet';
|
86
75
|
|
@@ -118,11 +107,12 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
118
107
|
'worklet';
|
119
108
|
|
120
109
|
const translationSpringConfig = {
|
121
|
-
|
122
|
-
|
123
|
-
stiffness:
|
110
|
+
mass: 2,
|
111
|
+
damping: 1000,
|
112
|
+
stiffness: 700,
|
124
113
|
velocity: velocityX,
|
125
114
|
overshootClamping: true,
|
115
|
+
reduceMotion: _reactNativeReanimated.ReduceMotion.System,
|
126
116
|
...animationOptions
|
127
117
|
};
|
128
118
|
const isClosing = toValue === 0;
|
@@ -139,31 +129,68 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
139
129
|
dispatchEndEvents(frozenRowState, toValue);
|
140
130
|
}
|
141
131
|
});
|
142
|
-
const progressTarget = toValue === 0 ? 0 : 1;
|
143
|
-
showLeftProgress.value =
|
144
|
-
showRightProgress.value =
|
132
|
+
const progressTarget = toValue === 0 ? 0 : 1 * Math.sign(toValue);
|
133
|
+
showLeftProgress.value = (0, _reactNativeReanimated.withSpring)(Math.max(progressTarget, 0), progressSpringConfig);
|
134
|
+
showRightProgress.value = (0, _reactNativeReanimated.withSpring)(Math.max(-progressTarget, 0), progressSpringConfig);
|
145
135
|
dispatchImmediateEvents(frozenRowState, toValue);
|
146
136
|
rowState.value = Math.sign(toValue);
|
147
137
|
}, [rowState, animationOptions, appliedTranslation, showLeftProgress, leftWidth, showRightProgress, rightWidth, dispatchImmediateEvents, dispatchEndEvents]);
|
138
|
+
const leftLayoutRef = (0, _reactNativeReanimated.useAnimatedRef)();
|
139
|
+
const leftWrapperLayoutRef = (0, _reactNativeReanimated.useAnimatedRef)();
|
140
|
+
const rightLayoutRef = (0, _reactNativeReanimated.useAnimatedRef)();
|
141
|
+
const updateElementWidths = (0, _react.useCallback)(() => {
|
142
|
+
'worklet';
|
143
|
+
|
144
|
+
var _leftLayout$pageX, _leftWrapperLayout$pa, _rightLayout$pageX, _leftWrapperLayout$pa2;
|
145
|
+
|
146
|
+
const leftLayout = (0, _reactNativeReanimated.measure)(leftLayoutRef);
|
147
|
+
const leftWrapperLayout = (0, _reactNativeReanimated.measure)(leftWrapperLayoutRef);
|
148
|
+
const rightLayout = (0, _reactNativeReanimated.measure)(rightLayoutRef);
|
149
|
+
leftWidth.value = ((_leftLayout$pageX = leftLayout === null || leftLayout === void 0 ? void 0 : leftLayout.pageX) !== null && _leftLayout$pageX !== void 0 ? _leftLayout$pageX : 0) - ((_leftWrapperLayout$pa = leftWrapperLayout === null || leftWrapperLayout === void 0 ? void 0 : leftWrapperLayout.pageX) !== null && _leftWrapperLayout$pa !== void 0 ? _leftWrapperLayout$pa : 0);
|
150
|
+
rightWidth.value = rowWidth.value - ((_rightLayout$pageX = rightLayout === null || rightLayout === void 0 ? void 0 : rightLayout.pageX) !== null && _rightLayout$pageX !== void 0 ? _rightLayout$pageX : rowWidth.value) + ((_leftWrapperLayout$pa2 = leftWrapperLayout === null || leftWrapperLayout === void 0 ? void 0 : leftWrapperLayout.pageX) !== null && _leftWrapperLayout$pa2 !== void 0 ? _leftWrapperLayout$pa2 : 0);
|
151
|
+
}, [leftLayoutRef, leftWrapperLayoutRef, rightLayoutRef, leftWidth, rightWidth, rowWidth.value]);
|
148
152
|
const swipeableMethods = (0, _react.useMemo)(() => ({
|
149
153
|
close() {
|
150
154
|
'worklet';
|
151
155
|
|
152
|
-
|
156
|
+
if (_WORKLET) {
|
157
|
+
animateRow(0);
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
|
161
|
+
(0, _reactNativeReanimated.runOnUI)(() => {
|
162
|
+
animateRow(0);
|
163
|
+
})();
|
153
164
|
},
|
154
165
|
|
155
166
|
openLeft() {
|
156
167
|
'worklet';
|
157
168
|
|
158
|
-
|
169
|
+
if (_WORKLET) {
|
170
|
+
updateElementWidths();
|
171
|
+
animateRow(leftWidth.value);
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
|
175
|
+
(0, _reactNativeReanimated.runOnUI)(() => {
|
176
|
+
updateElementWidths();
|
177
|
+
animateRow(leftWidth.value);
|
178
|
+
})();
|
159
179
|
},
|
160
180
|
|
161
181
|
openRight() {
|
162
|
-
'worklet';
|
182
|
+
'worklet';
|
163
183
|
|
164
|
-
|
184
|
+
if (_WORKLET) {
|
185
|
+
updateElementWidths();
|
186
|
+
animateRow(-rightWidth.value);
|
187
|
+
return;
|
188
|
+
}
|
165
189
|
|
166
|
-
|
190
|
+
(0, _reactNativeReanimated.runOnUI)(() => {
|
191
|
+
updateElementWidths();
|
192
|
+
animateRow(-rightWidth.value);
|
193
|
+
})();
|
167
194
|
},
|
168
195
|
|
169
196
|
reset() {
|
@@ -175,28 +202,35 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
175
202
|
rowState.value = 0;
|
176
203
|
}
|
177
204
|
|
178
|
-
}), [
|
205
|
+
}), [animateRow, updateElementWidths, leftWidth, rightWidth, userDrag, showLeftProgress, appliedTranslation, rowState]);
|
179
206
|
const onRowLayout = (0, _react.useCallback)(({
|
180
207
|
nativeEvent
|
181
208
|
}) => {
|
182
209
|
rowWidth.value = nativeEvent.layout.width;
|
183
|
-
}, [rowWidth]);
|
210
|
+
}, [rowWidth]); // As stated in `Dimensions.get` docstring, this function should be called on every render
|
211
|
+
// since dimensions may change (e.g. orientation change)
|
212
|
+
|
213
|
+
const leftActionAnimation = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
214
|
+
return {
|
215
|
+
opacity: showLeftProgress.value === 0 ? 0 : 1
|
216
|
+
};
|
217
|
+
});
|
184
218
|
const leftElement = (0, _react.useCallback)(() => /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
219
|
+
ref: leftWrapperLayoutRef,
|
220
|
+
style: [styles.leftActions, leftActionAnimation]
|
221
|
+
}, renderLeftActions === null || renderLeftActions === void 0 ? void 0 : renderLeftActions(showLeftProgress, appliedTranslation, swipeableMethods), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
222
|
+
ref: leftLayoutRef
|
223
|
+
})), [appliedTranslation, leftActionAnimation, leftLayoutRef, leftWrapperLayoutRef, renderLeftActions, showLeftProgress, swipeableMethods]);
|
224
|
+
const rightActionAnimation = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
225
|
+
return {
|
226
|
+
opacity: showRightProgress.value === 0 ? 0 : 1
|
227
|
+
};
|
228
|
+
});
|
191
229
|
const rightElement = (0, _react.useCallback)(() => /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
192
|
-
style: [styles.rightActions]
|
193
|
-
}, renderRightActions === null || renderRightActions === void 0 ? void 0 : renderRightActions(showRightProgress, appliedTranslation, swipeableMethods), /*#__PURE__*/_react.default.createElement(
|
194
|
-
|
195
|
-
|
196
|
-
}) => {
|
197
|
-
rightOffset.value = nativeEvent.layout.x;
|
198
|
-
}
|
199
|
-
})), [appliedTranslation, renderRightActions, rightOffset, showRightProgress, swipeableMethods]);
|
230
|
+
style: [styles.rightActions, rightActionAnimation]
|
231
|
+
}, renderRightActions === null || renderRightActions === void 0 ? void 0 : renderRightActions(showRightProgress, appliedTranslation, swipeableMethods), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
232
|
+
ref: rightLayoutRef
|
233
|
+
})), [appliedTranslation, renderRightActions, rightActionAnimation, rightLayoutRef, showRightProgress, swipeableMethods]);
|
200
234
|
const handleRelease = (0, _react.useCallback)(event => {
|
201
235
|
'worklet';
|
202
236
|
|
@@ -204,7 +238,6 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
204
238
|
velocityX
|
205
239
|
} = event;
|
206
240
|
userDrag.value = event.translationX;
|
207
|
-
updateRightElementWidth();
|
208
241
|
const leftThresholdProp = leftThreshold !== null && leftThreshold !== void 0 ? leftThreshold : leftWidth.value / 2;
|
209
242
|
const rightThresholdProp = rightThreshold !== null && rightThreshold !== void 0 ? rightThreshold : rightWidth.value / 2;
|
210
243
|
const translationX = (userDrag.value + DRAG_TOSS * velocityX) / friction;
|
@@ -229,7 +262,7 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
229
262
|
}
|
230
263
|
|
231
264
|
animateRow(toValue, velocityX / friction);
|
232
|
-
}, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag
|
265
|
+
}, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag]);
|
233
266
|
const close = (0, _react.useCallback)(() => {
|
234
267
|
'worklet';
|
235
268
|
|
@@ -241,9 +274,7 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
241
274
|
close();
|
242
275
|
}
|
243
276
|
}), [close, rowState]);
|
244
|
-
const panGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.Pan().enabled(enabled !== false).enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture).activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge]).onStart((
|
245
|
-
updateRightElementWidth();
|
246
|
-
}).onUpdate(event => {
|
277
|
+
const panGesture = (0, _react.useMemo)(() => _gestureObjects.GestureObjects.Pan().enabled(enabled !== false).enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture).activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge]).onStart(updateElementWidths).onUpdate(event => {
|
247
278
|
userDrag.value = event.translationX;
|
248
279
|
const direction = rowState.value === -1 ? SwipeDirection.RIGHT : rowState.value === 1 ? SwipeDirection.LEFT : event.translationX > 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT;
|
249
280
|
|
@@ -262,7 +293,7 @@ const Swipeable = /*#__PURE__*/(0, _react.forwardRef)(function Swipeable(props,
|
|
262
293
|
handleRelease(event);
|
263
294
|
}).onFinalize(() => {
|
264
295
|
dragStarted.value = false;
|
265
|
-
}), [dragOffsetFromLeftEdge, dragOffsetFromRightEdge, dragStarted, enableTrackpadTwoFingerGesture, enabled, handleRelease, onSwipeableCloseStartDrag, onSwipeableOpenStartDrag, rowState, updateAnimatedEvent,
|
296
|
+
}), [dragOffsetFromLeftEdge, dragOffsetFromRightEdge, dragStarted, enableTrackpadTwoFingerGesture, enabled, handleRelease, onSwipeableCloseStartDrag, onSwipeableOpenStartDrag, rowState, updateAnimatedEvent, updateElementWidths, userDrag]);
|
266
297
|
(0, _react.useImperativeHandle)(ref, () => swipeableMethods, [swipeableMethods]);
|
267
298
|
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
268
299
|
transform: [{
|
@@ -296,10 +327,12 @@ const styles = _reactNative.StyleSheet.create({
|
|
296
327
|
overflow: 'hidden'
|
297
328
|
},
|
298
329
|
leftActions: { ..._reactNative.StyleSheet.absoluteFillObject,
|
299
|
-
flexDirection: _reactNative.I18nManager.isRTL ? 'row-reverse' : 'row'
|
330
|
+
flexDirection: _reactNative.I18nManager.isRTL ? 'row-reverse' : 'row',
|
331
|
+
overflow: 'hidden'
|
300
332
|
},
|
301
333
|
rightActions: { ..._reactNative.StyleSheet.absoluteFillObject,
|
302
|
-
flexDirection: _reactNative.I18nManager.isRTL ? 'row' : 'row-reverse'
|
334
|
+
flexDirection: _reactNative.I18nManager.isRTL ? 'row' : 'row-reverse',
|
335
|
+
overflow: 'hidden'
|
303
336
|
}
|
304
337
|
});
|
305
338
|
//# sourceMappingURL=ReanimatedSwipeable.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["ReanimatedSwipeable.tsx"],"names":["DRAG_TOSS","SwipeDirection","Swipeable","props","ref","defaultProps","friction","overshootFriction","dragOffset","enableTrackpadTwoFingerGesture","leftThreshold","rightThreshold","enabled","containerStyle","childrenContainerStyle","animationOptions","overshootLeft","overshootRight","testID","children","dragOffsetFromLeftEdge","dragOffsetFromRightEdge","onSwipeableOpenStartDrag","onSwipeableCloseStartDrag","onSwipeableWillOpen","onSwipeableWillClose","onSwipeableOpen","onSwipeableClose","renderLeftActions","renderRightActions","remainingProps","rowState","userDrag","appliedTranslation","rowWidth","leftWidth","rightWidth","rightOffset","showLeftProgress","showRightProgress","updateRightElementWidth","value","Math","max","updateAnimatedEvent","shouldOvershootLeft","shouldOvershootRight","startOffset","offsetDrag","dispatchImmediateEvents","fromValue","toValue","RIGHT","LEFT","dispatchEndEvents","animateRow","velocityX","translationSpringConfig","duration","dampingRatio","stiffness","velocity","overshootClamping","isClosing","moveToRight","usedWidth","progressSpringConfig","restDisplacementThreshold","restSpeedThreshold","frozenRowState","isFinished","progressTarget","sign","swipeableMethods","close","openLeft","openRight","reset","onRowLayout","nativeEvent","layout","width","leftElement","styles","leftActions","x","rightElement","rightActions","handleRelease","event","translationX","leftThresholdProp","rightThresholdProp","dragStarted","tapGesture","Gesture","Tap","shouldCancelWhenOutside","onStart","panGesture","Pan","activeOffsetX","onUpdate","direction","onEnd","onFinalize","animatedStyle","transform","translateX","pointerEvents","swipeableComponent","container","StyleSheet","create","overflow","absoluteFillObject","flexDirection","I18nManager","isRTL"],"mappings":";;;;;;;AAIA;;AAOA;;AACA;;AAOA;;AAQA;;;;;;;;AASA,MAAMA,SAAS,GAAG,IAAlB;IAOKC,c;;WAAAA,c;AAAAA,EAAAA,c;AAAAA,EAAAA,c;GAAAA,c,KAAAA,c;;AAsKL,MAAMC,SAAS,gBAAG,uBAChB,SAASA,SAAT,CACEC,KADF,EAEEC,GAFF,EAGE;AACA,QAAMC,YAAY,GAAG;AACnBC,IAAAA,QAAQ,EAAE,CADS;AAEnBC,IAAAA,iBAAiB,EAAE,CAFA;AAGnBC,IAAAA,UAAU,EAAE,EAHO;AAInBC,IAAAA,8BAA8B,EAAE;AAJb,GAArB;AAOA,QAAM;AACJC,IAAAA,aADI;AAEJC,IAAAA,cAFI;AAGJC,IAAAA,OAHI;AAIJC,IA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to the DrawerLayout component this deserves to be put in a\n// separate repo. Although, keeping it here for the time being will allow us to\n// move faster and fix possible issues quicker\n\nimport React, {\n ForwardedRef,\n forwardRef,\n useCallback,\n useImperativeHandle,\n useMemo,\n} from 'react';\nimport { GestureObjects as Gesture } from '../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../handlers/gestures/GestureDetector';\nimport {\n GestureStateChangeEvent,\n GestureUpdateEvent,\n} from '../handlers/gestureHandlerCommon';\nimport type { PanGestureHandlerProps } from '../handlers/PanGestureHandler';\nimport type { PanGestureHandlerEventPayload } from '../handlers/GestureHandlerEventPayload';\nimport Animated, {\n SharedValue,\n interpolate,\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport {\n I18nManager,\n LayoutChangeEvent,\n StyleProp,\n StyleSheet,\n View,\n ViewStyle,\n} from 'react-native';\n\nconst DRAG_TOSS = 0.05;\n\ntype SwipeableExcludes = Exclude<\n keyof PanGestureHandlerProps,\n 'onGestureEvent' | 'onHandlerStateChange'\n>;\n\nenum SwipeDirection {\n LEFT = 'left',\n RIGHT = 'right',\n}\n\nexport interface SwipeableProps\n extends Pick<PanGestureHandlerProps, SwipeableExcludes> {\n /**\n * Enables two-finger gestures on supported devices, for example iPads with\n * trackpads. If not enabled the gesture will require click + drag, with\n * `enableTrackpadTwoFingerGesture` swiping with two fingers will also trigger\n * the gesture.\n */\n enableTrackpadTwoFingerGesture?: boolean;\n\n /**\n * Specifies how much the visual interaction will be delayed compared to the\n * gesture distance. e.g. value of 1 will indicate that the swipeable panel\n * should exactly follow the gesture, 2 means it is going to be two times\n * \"slower\".\n */\n friction?: number;\n\n /**\n * Distance from the left edge at which released panel will animate to the\n * open state (or the open panel will animate into the closed state). By\n * default it's a half of the panel's width.\n */\n leftThreshold?: number;\n\n /**\n * Distance from the right edge at which released panel will animate to the\n * open state (or the open panel will animate into the closed state). By\n * default it's a half of the panel's width.\n */\n rightThreshold?: number;\n\n /**\n * Distance that the panel must be dragged from the left edge to be considered\n * a swipe. The default value is 10.\n */\n dragOffsetFromLeftEdge?: number;\n\n /**\n * Distance that the panel must be dragged from the right edge to be considered\n * a swipe. The default value is 10.\n */\n dragOffsetFromRightEdge?: number;\n\n /**\n * Value indicating if the swipeable panel can be pulled further than the left\n * actions panel's width. It is set to true by default as long as the left\n * panel render method is present.\n */\n overshootLeft?: boolean;\n\n /**\n * Value indicating if the swipeable panel can be pulled further than the\n * right actions panel's width. It is set to true by default as long as the\n * right panel render method is present.\n */\n overshootRight?: boolean;\n\n /**\n * Specifies how much the visual interaction will be delayed compared to the\n * gesture distance at overshoot. Default value is 1, it mean no friction, for\n * a native feel, try 8 or above.\n */\n overshootFriction?: number;\n\n /**\n * Called when action panel gets open (either right or left).\n */\n onSwipeableOpen?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel is closed.\n */\n onSwipeableClose?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts animating on open (either right or left).\n */\n onSwipeableWillOpen?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts animating on close.\n */\n onSwipeableWillClose?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts being shown on dragging to open.\n */\n onSwipeableOpenStartDrag?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts being shown on dragging to close.\n */\n onSwipeableCloseStartDrag?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.\n * - When the element overshoots it's opened position the value tends towards `Infinity`.\n * - Goes back to `1` when `swipeable` is released.\n *\n * `translation`: a horizontal offset of the `swipeable` relative to its closed position.\\\n * `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.\n *\n * To support `rtl` flexbox layouts use `flexDirection` styling.\n * */\n renderLeftActions?: (\n progress: SharedValue<number>,\n translation: SharedValue<number>,\n swipeableMethods: SwipeableMethods\n ) => React.ReactNode;\n\n /**\n * `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.\n * - When the element overshoots it's opened position the value tends towards `Infinity`.\n * - Goes back to `1` when `swipeable` is released.\n *\n * `translation`: a horizontal offset of the `swipeable` relative to its closed position.\\\n * `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.\n *\n * To support `rtl` flexbox layouts use `flexDirection` styling.\n * */\n renderRightActions?: (\n progress: SharedValue<number>,\n translation: SharedValue<number>,\n swipeableMethods: SwipeableMethods\n ) => React.ReactNode;\n\n animationOptions?: Record<string, unknown>;\n\n /**\n * Style object for the container (`Animated.View`), for example to override\n * `overflow: 'hidden'`.\n */\n containerStyle?: StyleProp<ViewStyle>;\n\n /**\n * Style object for the children container (`Animated.View`), for example to\n * apply `flex: 1`\n */\n childrenContainerStyle?: StyleProp<ViewStyle>;\n}\n\nexport interface SwipeableMethods {\n close: () => void;\n openLeft: () => void;\n openRight: () => void;\n reset: () => void;\n}\n\nconst Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(\n function Swipeable(\n props: SwipeableProps,\n ref: ForwardedRef<SwipeableMethods>\n ) {\n const defaultProps = {\n friction: 1,\n overshootFriction: 1,\n dragOffset: 10,\n enableTrackpadTwoFingerGesture: false,\n };\n\n const {\n leftThreshold,\n rightThreshold,\n enabled,\n containerStyle,\n childrenContainerStyle,\n animationOptions,\n overshootLeft,\n overshootRight,\n testID,\n children,\n enableTrackpadTwoFingerGesture = defaultProps.enableTrackpadTwoFingerGesture,\n dragOffsetFromLeftEdge = defaultProps.dragOffset,\n dragOffsetFromRightEdge = defaultProps.dragOffset,\n friction = defaultProps.friction,\n overshootFriction = defaultProps.overshootFriction,\n onSwipeableOpenStartDrag,\n onSwipeableCloseStartDrag,\n onSwipeableWillOpen,\n onSwipeableWillClose,\n onSwipeableOpen,\n onSwipeableClose,\n renderLeftActions,\n renderRightActions,\n ...remainingProps\n } = props;\n\n const rowState = useSharedValue<number>(0);\n\n const userDrag = useSharedValue<number>(0);\n\n const appliedTranslation = useSharedValue<number>(0);\n\n const rowWidth = useSharedValue<number>(0);\n const leftWidth = useSharedValue<number>(0);\n const rightWidth = useSharedValue<number>(0);\n\n // used for synchronizing layout measurements between JS and UI\n const rightOffset = useSharedValue<number | null>(null);\n\n const showLeftProgress = useSharedValue<number>(0);\n const showRightProgress = useSharedValue<number>(0);\n\n const updateRightElementWidth = useCallback(() => {\n 'worklet';\n if (rightOffset.value === null) {\n rightOffset.value = rowWidth.value;\n }\n rightWidth.value = Math.max(0, rowWidth.value - rightOffset.value);\n }, [rightOffset, rightWidth, rowWidth]);\n\n const updateAnimatedEvent = useCallback(() => {\n 'worklet';\n\n const shouldOvershootLeft = overshootLeft ?? leftWidth.value > 0;\n const shouldOvershootRight = overshootRight ?? rightWidth.value > 0;\n\n const startOffset =\n rowState.value === 1\n ? leftWidth.value\n : rowState.value === -1\n ? -rightWidth.value\n : 0;\n\n const offsetDrag = userDrag.value / friction + startOffset;\n\n appliedTranslation.value = interpolate(\n offsetDrag,\n [\n -rightWidth.value - 1,\n -rightWidth.value,\n leftWidth.value,\n leftWidth.value + 1,\n ],\n [\n -rightWidth.value -\n (shouldOvershootRight ? 1 / overshootFriction : 0),\n -rightWidth.value,\n leftWidth.value,\n leftWidth.value + (shouldOvershootLeft ? 1 / overshootFriction : 0),\n ]\n );\n\n showLeftProgress.value =\n leftWidth.value > 0\n ? interpolate(\n appliedTranslation.value,\n [-1, 0, leftWidth.value],\n [0, 0, 1]\n )\n : 0;\n\n showRightProgress.value =\n rightWidth.value > 0\n ? interpolate(\n appliedTranslation.value,\n [-rightWidth.value, 0, 1],\n [1, 0, 0]\n )\n : 0;\n }, [\n appliedTranslation,\n friction,\n leftWidth,\n overshootFriction,\n rightWidth,\n rowState,\n showLeftProgress,\n showRightProgress,\n userDrag,\n overshootLeft,\n overshootRight,\n ]);\n\n const dispatchImmediateEvents = useCallback(\n (fromValue: number, toValue: number) => {\n 'worklet';\n if (toValue > 0 && onSwipeableWillOpen) {\n runOnJS(onSwipeableWillOpen)(SwipeDirection.RIGHT);\n } else if (toValue < 0 && onSwipeableWillOpen) {\n runOnJS(onSwipeableWillOpen)(SwipeDirection.LEFT);\n } else if (onSwipeableWillClose) {\n runOnJS(onSwipeableWillClose)(\n fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT\n );\n }\n },\n [onSwipeableWillClose, onSwipeableWillOpen]\n );\n\n const dispatchEndEvents = useCallback(\n (fromValue: number, toValue: number) => {\n 'worklet';\n if (toValue > 0 && onSwipeableOpen) {\n runOnJS(onSwipeableOpen)(SwipeDirection.RIGHT);\n } else if (toValue < 0 && onSwipeableOpen) {\n runOnJS(onSwipeableOpen)(SwipeDirection.LEFT);\n } else if (onSwipeableClose) {\n runOnJS(onSwipeableClose)(\n fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT\n );\n }\n },\n [onSwipeableClose, onSwipeableOpen]\n );\n\n const animateRow: (toValue: number, velocityX?: number) => void =\n useCallback(\n (toValue: number, velocityX?: number) => {\n 'worklet';\n\n const translationSpringConfig = {\n duration: 1000,\n dampingRatio: 0.9,\n stiffness: 500,\n velocity: velocityX,\n overshootClamping: true,\n ...animationOptions,\n };\n\n const isClosing = toValue === 0;\n const moveToRight = isClosing ? rowState.value < 0 : toValue > 0;\n\n const usedWidth = isClosing\n ? moveToRight\n ? rightWidth.value\n : leftWidth.value\n : moveToRight\n ? leftWidth.value\n : rightWidth.value;\n\n const progressSpringConfig = {\n ...translationSpringConfig,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n velocity:\n velocityX &&\n interpolate(velocityX, [-usedWidth, usedWidth], [-1, 1]),\n };\n\n const frozenRowState = rowState.value;\n\n appliedTranslation.value = withSpring(\n toValue,\n translationSpringConfig,\n (isFinished) => {\n if (isFinished) {\n dispatchEndEvents(frozenRowState, toValue);\n }\n }\n );\n\n const progressTarget = toValue === 0 ? 0 : 1;\n\n showLeftProgress.value =\n leftWidth.value > 0\n ? withSpring(progressTarget, progressSpringConfig)\n : 0;\n showRightProgress.value =\n rightWidth.value > 0\n ? withSpring(progressTarget, progressSpringConfig)\n : 0;\n\n dispatchImmediateEvents(frozenRowState, toValue);\n\n rowState.value = Math.sign(toValue);\n },\n [\n rowState,\n animationOptions,\n appliedTranslation,\n showLeftProgress,\n leftWidth,\n showRightProgress,\n rightWidth,\n dispatchImmediateEvents,\n dispatchEndEvents,\n ]\n );\n\n const swipeableMethods = useMemo<SwipeableMethods>(\n () => ({\n close() {\n 'worklet';\n animateRow(0);\n },\n openLeft() {\n 'worklet';\n animateRow(leftWidth.value);\n },\n openRight() {\n 'worklet';\n // rightOffset and rowWidth are already much sooner than rightWidth\n animateRow((rightOffset.value ?? 0) - rowWidth.value);\n },\n reset() {\n 'worklet';\n userDrag.value = 0;\n showLeftProgress.value = 0;\n appliedTranslation.value = 0;\n rowState.value = 0;\n },\n }),\n [\n leftWidth,\n rightOffset,\n rowWidth,\n userDrag,\n showLeftProgress,\n appliedTranslation,\n rowState,\n animateRow,\n ]\n );\n\n const onRowLayout = useCallback(\n ({ nativeEvent }: LayoutChangeEvent) => {\n rowWidth.value = nativeEvent.layout.width;\n },\n [rowWidth]\n );\n\n const leftElement = useCallback(\n () => (\n <Animated.View style={[styles.leftActions]}>\n {renderLeftActions?.(\n showLeftProgress,\n appliedTranslation,\n swipeableMethods\n )}\n <View\n onLayout={({ nativeEvent }) =>\n (leftWidth.value = nativeEvent.layout.x)\n }\n />\n </Animated.View>\n ),\n [\n appliedTranslation,\n leftWidth,\n renderLeftActions,\n showLeftProgress,\n swipeableMethods,\n ]\n );\n\n const rightElement = useCallback(\n () => (\n <Animated.View style={[styles.rightActions]}>\n {renderRightActions?.(\n showRightProgress,\n appliedTranslation,\n swipeableMethods\n )}\n <View\n onLayout={({ nativeEvent }) => {\n rightOffset.value = nativeEvent.layout.x;\n }}\n />\n </Animated.View>\n ),\n [\n appliedTranslation,\n renderRightActions,\n rightOffset,\n showRightProgress,\n swipeableMethods,\n ]\n );\n\n const handleRelease = useCallback(\n (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {\n 'worklet';\n const { velocityX } = event;\n userDrag.value = event.translationX;\n\n updateRightElementWidth();\n\n const leftThresholdProp = leftThreshold ?? leftWidth.value / 2;\n const rightThresholdProp = rightThreshold ?? rightWidth.value / 2;\n\n const translationX =\n (userDrag.value + DRAG_TOSS * velocityX) / friction;\n\n let toValue = 0;\n\n if (rowState.value === 0) {\n if (translationX > leftThresholdProp) {\n toValue = leftWidth.value;\n } else if (translationX < -rightThresholdProp) {\n toValue = -rightWidth.value;\n }\n } else if (rowState.value === 1) {\n // Swiped to left\n if (translationX > -leftThresholdProp) {\n toValue = leftWidth.value;\n }\n } else {\n // Swiped to right\n if (translationX < rightThresholdProp) {\n toValue = -rightWidth.value;\n }\n }\n\n animateRow(toValue, velocityX / friction);\n },\n [\n animateRow,\n friction,\n leftThreshold,\n leftWidth,\n rightThreshold,\n rightWidth,\n rowState,\n userDrag,\n updateRightElementWidth,\n ]\n );\n\n const close = useCallback(() => {\n 'worklet';\n animateRow(0);\n }, [animateRow]);\n\n const dragStarted = useSharedValue<boolean>(false);\n\n const tapGesture = useMemo(\n () =>\n Gesture.Tap()\n .shouldCancelWhenOutside(true)\n .onStart(() => {\n if (rowState.value !== 0) {\n close();\n }\n }),\n [close, rowState]\n );\n\n const panGesture = useMemo(\n () =>\n Gesture.Pan()\n .enabled(enabled !== false)\n .enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture)\n .activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge])\n .onStart(() => {\n updateRightElementWidth();\n })\n .onUpdate(\n (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {\n userDrag.value = event.translationX;\n\n const direction =\n rowState.value === -1\n ? SwipeDirection.RIGHT\n : rowState.value === 1\n ? SwipeDirection.LEFT\n : event.translationX > 0\n ? SwipeDirection.RIGHT\n : SwipeDirection.LEFT;\n\n if (!dragStarted.value) {\n dragStarted.value = true;\n if (rowState.value === 0 && onSwipeableOpenStartDrag) {\n runOnJS(onSwipeableOpenStartDrag)(direction);\n } else if (onSwipeableCloseStartDrag) {\n runOnJS(onSwipeableCloseStartDrag)(direction);\n }\n }\n\n updateAnimatedEvent();\n }\n )\n .onEnd(\n (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {\n handleRelease(event);\n }\n )\n .onFinalize(() => {\n dragStarted.value = false;\n }),\n [\n dragOffsetFromLeftEdge,\n dragOffsetFromRightEdge,\n dragStarted,\n enableTrackpadTwoFingerGesture,\n enabled,\n handleRelease,\n onSwipeableCloseStartDrag,\n onSwipeableOpenStartDrag,\n rowState,\n updateAnimatedEvent,\n updateRightElementWidth,\n userDrag,\n ]\n );\n\n useImperativeHandle(ref, () => swipeableMethods, [swipeableMethods]);\n\n const animatedStyle = useAnimatedStyle(\n () => ({\n transform: [{ translateX: appliedTranslation.value }],\n pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',\n }),\n [appliedTranslation, rowState]\n );\n\n const swipeableComponent = (\n <GestureDetector gesture={panGesture} touchAction=\"pan-y\">\n <Animated.View\n {...remainingProps}\n onLayout={onRowLayout}\n style={[styles.container, containerStyle]}>\n {leftElement()}\n {rightElement()}\n <GestureDetector gesture={tapGesture} touchAction=\"pan-y\">\n <Animated.View style={[animatedStyle, childrenContainerStyle]}>\n {children}\n </Animated.View>\n </GestureDetector>\n </Animated.View>\n </GestureDetector>\n );\n\n return testID ? (\n <View testID={testID}>{swipeableComponent}</View>\n ) : (\n swipeableComponent\n );\n }\n);\n\nexport default Swipeable;\nexport type SwipeableRef = ForwardedRef<SwipeableMethods>;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n leftActions: {\n ...StyleSheet.absoluteFillObject,\n flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',\n },\n rightActions: {\n ...StyleSheet.absoluteFillObject,\n flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',\n },\n});\n"]}
|
1
|
+
{"version":3,"sources":["ReanimatedSwipeable.tsx"],"names":["DRAG_TOSS","SwipeDirection","Swipeable","props","ref","defaultProps","friction","overshootFriction","dragOffset","enableTrackpadTwoFingerGesture","leftThreshold","rightThreshold","enabled","containerStyle","childrenContainerStyle","animationOptions","overshootLeft","overshootRight","testID","children","dragOffsetFromLeftEdge","dragOffsetFromRightEdge","onSwipeableOpenStartDrag","onSwipeableCloseStartDrag","onSwipeableWillOpen","onSwipeableWillClose","onSwipeableOpen","onSwipeableClose","renderLeftActions","renderRightActions","remainingProps","rowState","userDrag","appliedTranslation","rowWidth","leftWidth","rightWidth","showLeftProgress","showRightProgress","updateAnimatedEvent","shouldOvershootLeft","value","shouldOvershootRight","startOffset","offsetDrag","dispatchImmediateEvents","fromValue","toValue","RIGHT","LEFT","dispatchEndEvents","animateRow","velocityX","translationSpringConfig","mass","damping","stiffness","velocity","overshootClamping","reduceMotion","ReduceMotion","System","isClosing","moveToRight","usedWidth","progressSpringConfig","restDisplacementThreshold","restSpeedThreshold","frozenRowState","isFinished","progressTarget","Math","sign","max","leftLayoutRef","leftWrapperLayoutRef","rightLayoutRef","updateElementWidths","leftLayout","leftWrapperLayout","rightLayout","pageX","swipeableMethods","close","_WORKLET","openLeft","openRight","reset","onRowLayout","nativeEvent","layout","width","leftActionAnimation","opacity","leftElement","styles","leftActions","rightActionAnimation","rightElement","rightActions","handleRelease","event","translationX","leftThresholdProp","rightThresholdProp","dragStarted","tapGesture","Gesture","Tap","shouldCancelWhenOutside","onStart","panGesture","Pan","activeOffsetX","onUpdate","direction","onEnd","onFinalize","animatedStyle","transform","translateX","pointerEvents","swipeableComponent","container","StyleSheet","create","overflow","absoluteFillObject","flexDirection","I18nManager","isRTL"],"mappings":";;;;;;;AAIA;;AAOA;;AACA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AAQ,EAAE;AADD,GADoB;AAI/B9B,EAAAA,WAAW,EAAE,EACX,GAAG4B,wBAAWG,kBADH;AAEXC,IAAAA,aAAa,EAAEC,yBAAYC,KAAZ,GAAoB,aAApB,GAAoC,KAFxC;AAGXJ,IAAAA,QAAQ,EAAE;AAHC,GAJkB;AAS/B3B,EAAAA,YAAY,EAAE,EACZ,GAAGyB,wBAAWG,kBADF;AAEZC,IAAAA,aAAa,EAAEC,yBAAYC,KAAZ,GAAoB,KAApB,GAA4B,aAF/B;AAGZJ,IAAAA,QAAQ,EAAE;AAHE;AATiB,CAAlB,CAAf","sourcesContent":["// Similarily to the DrawerLayout component this deserves to be put in a\n// separate repo. Although, keeping it here for the time being will allow us to\n// move faster and fix possible issues quicker\n\nimport React, {\n ForwardedRef,\n forwardRef,\n useCallback,\n useImperativeHandle,\n useMemo,\n} from 'react';\nimport { GestureObjects as Gesture } from '../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../handlers/gestures/GestureDetector';\nimport {\n GestureStateChangeEvent,\n GestureUpdateEvent,\n} from '../handlers/gestureHandlerCommon';\nimport type { PanGestureHandlerProps } from '../handlers/PanGestureHandler';\nimport type { PanGestureHandlerEventPayload } from '../handlers/GestureHandlerEventPayload';\nimport Animated, {\n ReduceMotion,\n SharedValue,\n interpolate,\n measure,\n runOnJS,\n runOnUI,\n useAnimatedRef,\n useAnimatedStyle,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\nimport {\n I18nManager,\n LayoutChangeEvent,\n StyleProp,\n StyleSheet,\n View,\n ViewStyle,\n} from 'react-native';\n\nconst DRAG_TOSS = 0.05;\n\ntype SwipeableExcludes = Exclude<\n keyof PanGestureHandlerProps,\n 'onGestureEvent' | 'onHandlerStateChange'\n>;\n\nenum SwipeDirection {\n LEFT = 'left',\n RIGHT = 'right',\n}\n\nexport interface SwipeableProps\n extends Pick<PanGestureHandlerProps, SwipeableExcludes> {\n /**\n * Enables two-finger gestures on supported devices, for example iPads with\n * trackpads. If not enabled the gesture will require click + drag, with\n * `enableTrackpadTwoFingerGesture` swiping with two fingers will also trigger\n * the gesture.\n */\n enableTrackpadTwoFingerGesture?: boolean;\n\n /**\n * Specifies how much the visual interaction will be delayed compared to the\n * gesture distance. e.g. value of 1 will indicate that the swipeable panel\n * should exactly follow the gesture, 2 means it is going to be two times\n * \"slower\".\n */\n friction?: number;\n\n /**\n * Distance from the left edge at which released panel will animate to the\n * open state (or the open panel will animate into the closed state). By\n * default it's a half of the panel's width.\n */\n leftThreshold?: number;\n\n /**\n * Distance from the right edge at which released panel will animate to the\n * open state (or the open panel will animate into the closed state). By\n * default it's a half of the panel's width.\n */\n rightThreshold?: number;\n\n /**\n * Distance that the panel must be dragged from the left edge to be considered\n * a swipe. The default value is 10.\n */\n dragOffsetFromLeftEdge?: number;\n\n /**\n * Distance that the panel must be dragged from the right edge to be considered\n * a swipe. The default value is 10.\n */\n dragOffsetFromRightEdge?: number;\n\n /**\n * Value indicating if the swipeable panel can be pulled further than the left\n * actions panel's width. It is set to true by default as long as the left\n * panel render method is present.\n */\n overshootLeft?: boolean;\n\n /**\n * Value indicating if the swipeable panel can be pulled further than the\n * right actions panel's width. It is set to true by default as long as the\n * right panel render method is present.\n */\n overshootRight?: boolean;\n\n /**\n * Specifies how much the visual interaction will be delayed compared to the\n * gesture distance at overshoot. Default value is 1, it mean no friction, for\n * a native feel, try 8 or above.\n */\n overshootFriction?: number;\n\n /**\n * Called when action panel gets open (either right or left).\n */\n onSwipeableOpen?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel is closed.\n */\n onSwipeableClose?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts animating on open (either right or left).\n */\n onSwipeableWillOpen?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts animating on close.\n */\n onSwipeableWillClose?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts being shown on dragging to open.\n */\n onSwipeableOpenStartDrag?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * Called when action panel starts being shown on dragging to close.\n */\n onSwipeableCloseStartDrag?: (\n direction: SwipeDirection.LEFT | SwipeDirection.RIGHT\n ) => void;\n\n /**\n * `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.\n * - When the element overshoots it's opened position the value tends towards `Infinity`.\n * - Goes back to `1` when `swipeable` is released.\n *\n * `translation`: a horizontal offset of the `swipeable` relative to its closed position.\\\n * `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.\n *\n * To support `rtl` flexbox layouts use `flexDirection` styling.\n * */\n renderLeftActions?: (\n progress: SharedValue<number>,\n translation: SharedValue<number>,\n swipeableMethods: SwipeableMethods\n ) => React.ReactNode;\n\n /**\n * `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.\n * - When the element overshoots it's opened position the value tends towards `Infinity`.\n * - Goes back to `1` when `swipeable` is released.\n *\n * `translation`: a horizontal offset of the `swipeable` relative to its closed position.\\\n * `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.\n *\n * To support `rtl` flexbox layouts use `flexDirection` styling.\n * */\n renderRightActions?: (\n progress: SharedValue<number>,\n translation: SharedValue<number>,\n swipeableMethods: SwipeableMethods\n ) => React.ReactNode;\n\n animationOptions?: Record<string, unknown>;\n\n /**\n * Style object for the container (`Animated.View`), for example to override\n * `overflow: 'hidden'`.\n */\n containerStyle?: StyleProp<ViewStyle>;\n\n /**\n * Style object for the children container (`Animated.View`), for example to\n * apply `flex: 1`\n */\n childrenContainerStyle?: StyleProp<ViewStyle>;\n}\n\nexport interface SwipeableMethods {\n close: () => void;\n openLeft: () => void;\n openRight: () => void;\n reset: () => void;\n}\n\nconst Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(\n function Swipeable(\n props: SwipeableProps,\n ref: ForwardedRef<SwipeableMethods>\n ) {\n const defaultProps = {\n friction: 1,\n overshootFriction: 1,\n dragOffset: 10,\n enableTrackpadTwoFingerGesture: false,\n };\n\n const {\n leftThreshold,\n rightThreshold,\n enabled,\n containerStyle,\n childrenContainerStyle,\n animationOptions,\n overshootLeft,\n overshootRight,\n testID,\n children,\n enableTrackpadTwoFingerGesture = defaultProps.enableTrackpadTwoFingerGesture,\n dragOffsetFromLeftEdge = defaultProps.dragOffset,\n dragOffsetFromRightEdge = defaultProps.dragOffset,\n friction = defaultProps.friction,\n overshootFriction = defaultProps.overshootFriction,\n onSwipeableOpenStartDrag,\n onSwipeableCloseStartDrag,\n onSwipeableWillOpen,\n onSwipeableWillClose,\n onSwipeableOpen,\n onSwipeableClose,\n renderLeftActions,\n renderRightActions,\n ...remainingProps\n } = props;\n\n const rowState = useSharedValue<number>(0);\n\n const userDrag = useSharedValue<number>(0);\n\n const appliedTranslation = useSharedValue<number>(0);\n\n const rowWidth = useSharedValue<number>(0);\n const leftWidth = useSharedValue<number>(0);\n const rightWidth = useSharedValue<number>(0);\n\n const showLeftProgress = useSharedValue<number>(0);\n const showRightProgress = useSharedValue<number>(0);\n\n const updateAnimatedEvent = useCallback(() => {\n 'worklet';\n\n const shouldOvershootLeft = overshootLeft ?? leftWidth.value > 0;\n const shouldOvershootRight = overshootRight ?? rightWidth.value > 0;\n\n const startOffset =\n rowState.value === 1\n ? leftWidth.value\n : rowState.value === -1\n ? -rightWidth.value\n : 0;\n\n const offsetDrag = userDrag.value / friction + startOffset;\n\n appliedTranslation.value = interpolate(\n offsetDrag,\n [\n -rightWidth.value - 1,\n -rightWidth.value,\n leftWidth.value,\n leftWidth.value + 1,\n ],\n [\n -rightWidth.value -\n (shouldOvershootRight ? 1 / overshootFriction : 0),\n -rightWidth.value,\n leftWidth.value,\n leftWidth.value + (shouldOvershootLeft ? 1 / overshootFriction : 0),\n ]\n );\n\n showLeftProgress.value =\n leftWidth.value > 0\n ? interpolate(\n appliedTranslation.value,\n [-1, 0, leftWidth.value],\n [0, 0, 1]\n )\n : 0;\n\n showRightProgress.value =\n rightWidth.value > 0\n ? interpolate(\n appliedTranslation.value,\n [-rightWidth.value, 0, 1],\n [1, 0, 0]\n )\n : 0;\n }, [\n appliedTranslation,\n friction,\n leftWidth,\n overshootFriction,\n rightWidth,\n rowState,\n showLeftProgress,\n showRightProgress,\n userDrag,\n overshootLeft,\n overshootRight,\n ]);\n\n const dispatchImmediateEvents = useCallback(\n (fromValue: number, toValue: number) => {\n 'worklet';\n if (toValue > 0 && onSwipeableWillOpen) {\n runOnJS(onSwipeableWillOpen)(SwipeDirection.RIGHT);\n } else if (toValue < 0 && onSwipeableWillOpen) {\n runOnJS(onSwipeableWillOpen)(SwipeDirection.LEFT);\n } else if (onSwipeableWillClose) {\n runOnJS(onSwipeableWillClose)(\n fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT\n );\n }\n },\n [onSwipeableWillClose, onSwipeableWillOpen]\n );\n\n const dispatchEndEvents = useCallback(\n (fromValue: number, toValue: number) => {\n 'worklet';\n if (toValue > 0 && onSwipeableOpen) {\n runOnJS(onSwipeableOpen)(SwipeDirection.RIGHT);\n } else if (toValue < 0 && onSwipeableOpen) {\n runOnJS(onSwipeableOpen)(SwipeDirection.LEFT);\n } else if (onSwipeableClose) {\n runOnJS(onSwipeableClose)(\n fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT\n );\n }\n },\n [onSwipeableClose, onSwipeableOpen]\n );\n\n const animateRow: (toValue: number, velocityX?: number) => void =\n useCallback(\n (toValue: number, velocityX?: number) => {\n 'worklet';\n\n const translationSpringConfig = {\n mass: 2,\n damping: 1000,\n stiffness: 700,\n velocity: velocityX,\n overshootClamping: true,\n reduceMotion: ReduceMotion.System,\n ...animationOptions,\n };\n\n const isClosing = toValue === 0;\n const moveToRight = isClosing ? rowState.value < 0 : toValue > 0;\n\n const usedWidth = isClosing\n ? moveToRight\n ? rightWidth.value\n : leftWidth.value\n : moveToRight\n ? leftWidth.value\n : rightWidth.value;\n\n const progressSpringConfig = {\n ...translationSpringConfig,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n velocity:\n velocityX &&\n interpolate(velocityX, [-usedWidth, usedWidth], [-1, 1]),\n };\n\n const frozenRowState = rowState.value;\n\n appliedTranslation.value = withSpring(\n toValue,\n translationSpringConfig,\n (isFinished) => {\n if (isFinished) {\n dispatchEndEvents(frozenRowState, toValue);\n }\n }\n );\n\n const progressTarget = toValue === 0 ? 0 : 1 * Math.sign(toValue);\n\n showLeftProgress.value = withSpring(\n Math.max(progressTarget, 0),\n progressSpringConfig\n );\n\n showRightProgress.value = withSpring(\n Math.max(-progressTarget, 0),\n progressSpringConfig\n );\n\n dispatchImmediateEvents(frozenRowState, toValue);\n\n rowState.value = Math.sign(toValue);\n },\n [\n rowState,\n animationOptions,\n appliedTranslation,\n showLeftProgress,\n leftWidth,\n showRightProgress,\n rightWidth,\n dispatchImmediateEvents,\n dispatchEndEvents,\n ]\n );\n\n const leftLayoutRef = useAnimatedRef();\n const leftWrapperLayoutRef = useAnimatedRef();\n const rightLayoutRef = useAnimatedRef();\n\n const updateElementWidths = useCallback(() => {\n 'worklet';\n const leftLayout = measure(leftLayoutRef);\n const leftWrapperLayout = measure(leftWrapperLayoutRef);\n const rightLayout = measure(rightLayoutRef);\n leftWidth.value =\n (leftLayout?.pageX ?? 0) - (leftWrapperLayout?.pageX ?? 0);\n\n rightWidth.value =\n rowWidth.value -\n (rightLayout?.pageX ?? rowWidth.value) +\n (leftWrapperLayout?.pageX ?? 0);\n }, [\n leftLayoutRef,\n leftWrapperLayoutRef,\n rightLayoutRef,\n leftWidth,\n rightWidth,\n rowWidth.value,\n ]);\n\n const swipeableMethods = useMemo<SwipeableMethods>(\n () => ({\n close() {\n 'worklet';\n if (_WORKLET) {\n animateRow(0);\n return;\n }\n runOnUI(() => {\n animateRow(0);\n })();\n },\n openLeft() {\n 'worklet';\n if (_WORKLET) {\n updateElementWidths();\n animateRow(leftWidth.value);\n return;\n }\n runOnUI(() => {\n updateElementWidths();\n animateRow(leftWidth.value);\n })();\n },\n openRight() {\n 'worklet';\n if (_WORKLET) {\n updateElementWidths();\n animateRow(-rightWidth.value);\n return;\n }\n runOnUI(() => {\n updateElementWidths();\n animateRow(-rightWidth.value);\n })();\n },\n reset() {\n 'worklet';\n userDrag.value = 0;\n showLeftProgress.value = 0;\n appliedTranslation.value = 0;\n rowState.value = 0;\n },\n }),\n [\n animateRow,\n updateElementWidths,\n leftWidth,\n rightWidth,\n userDrag,\n showLeftProgress,\n appliedTranslation,\n rowState,\n ]\n );\n\n const onRowLayout = useCallback(\n ({ nativeEvent }: LayoutChangeEvent) => {\n rowWidth.value = nativeEvent.layout.width;\n },\n [rowWidth]\n );\n\n // As stated in `Dimensions.get` docstring, this function should be called on every render\n // since dimensions may change (e.g. orientation change)\n\n const leftActionAnimation = useAnimatedStyle(() => {\n return {\n opacity: showLeftProgress.value === 0 ? 0 : 1,\n };\n });\n\n const leftElement = useCallback(\n () => (\n <Animated.View\n ref={leftWrapperLayoutRef}\n style={[styles.leftActions, leftActionAnimation]}>\n {renderLeftActions?.(\n showLeftProgress,\n appliedTranslation,\n swipeableMethods\n )}\n <Animated.View ref={leftLayoutRef} />\n </Animated.View>\n ),\n [\n appliedTranslation,\n leftActionAnimation,\n leftLayoutRef,\n leftWrapperLayoutRef,\n renderLeftActions,\n showLeftProgress,\n swipeableMethods,\n ]\n );\n\n const rightActionAnimation = useAnimatedStyle(() => {\n return {\n opacity: showRightProgress.value === 0 ? 0 : 1,\n };\n });\n\n const rightElement = useCallback(\n () => (\n <Animated.View style={[styles.rightActions, rightActionAnimation]}>\n {renderRightActions?.(\n showRightProgress,\n appliedTranslation,\n swipeableMethods\n )}\n <Animated.View ref={rightLayoutRef} />\n </Animated.View>\n ),\n [\n appliedTranslation,\n renderRightActions,\n rightActionAnimation,\n rightLayoutRef,\n showRightProgress,\n swipeableMethods,\n ]\n );\n\n const handleRelease = useCallback(\n (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {\n 'worklet';\n const { velocityX } = event;\n userDrag.value = event.translationX;\n\n const leftThresholdProp = leftThreshold ?? leftWidth.value / 2;\n const rightThresholdProp = rightThreshold ?? rightWidth.value / 2;\n\n const translationX =\n (userDrag.value + DRAG_TOSS * velocityX) / friction;\n\n let toValue = 0;\n\n if (rowState.value === 0) {\n if (translationX > leftThresholdProp) {\n toValue = leftWidth.value;\n } else if (translationX < -rightThresholdProp) {\n toValue = -rightWidth.value;\n }\n } else if (rowState.value === 1) {\n // Swiped to left\n if (translationX > -leftThresholdProp) {\n toValue = leftWidth.value;\n }\n } else {\n // Swiped to right\n if (translationX < rightThresholdProp) {\n toValue = -rightWidth.value;\n }\n }\n\n animateRow(toValue, velocityX / friction);\n },\n [\n animateRow,\n friction,\n leftThreshold,\n leftWidth,\n rightThreshold,\n rightWidth,\n rowState,\n userDrag,\n ]\n );\n\n const close = useCallback(() => {\n 'worklet';\n animateRow(0);\n }, [animateRow]);\n\n const dragStarted = useSharedValue<boolean>(false);\n\n const tapGesture = useMemo(\n () =>\n Gesture.Tap()\n .shouldCancelWhenOutside(true)\n .onStart(() => {\n if (rowState.value !== 0) {\n close();\n }\n }),\n [close, rowState]\n );\n\n const panGesture = useMemo(\n () =>\n Gesture.Pan()\n .enabled(enabled !== false)\n .enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture)\n .activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge])\n .onStart(updateElementWidths)\n .onUpdate(\n (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {\n userDrag.value = event.translationX;\n\n const direction =\n rowState.value === -1\n ? SwipeDirection.RIGHT\n : rowState.value === 1\n ? SwipeDirection.LEFT\n : event.translationX > 0\n ? SwipeDirection.RIGHT\n : SwipeDirection.LEFT;\n\n if (!dragStarted.value) {\n dragStarted.value = true;\n if (rowState.value === 0 && onSwipeableOpenStartDrag) {\n runOnJS(onSwipeableOpenStartDrag)(direction);\n } else if (onSwipeableCloseStartDrag) {\n runOnJS(onSwipeableCloseStartDrag)(direction);\n }\n }\n\n updateAnimatedEvent();\n }\n )\n .onEnd(\n (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {\n handleRelease(event);\n }\n )\n .onFinalize(() => {\n dragStarted.value = false;\n }),\n [\n dragOffsetFromLeftEdge,\n dragOffsetFromRightEdge,\n dragStarted,\n enableTrackpadTwoFingerGesture,\n enabled,\n handleRelease,\n onSwipeableCloseStartDrag,\n onSwipeableOpenStartDrag,\n rowState,\n updateAnimatedEvent,\n updateElementWidths,\n userDrag,\n ]\n );\n\n useImperativeHandle(ref, () => swipeableMethods, [swipeableMethods]);\n\n const animatedStyle = useAnimatedStyle(\n () => ({\n transform: [{ translateX: appliedTranslation.value }],\n pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',\n }),\n [appliedTranslation, rowState]\n );\n\n const swipeableComponent = (\n <GestureDetector gesture={panGesture} touchAction=\"pan-y\">\n <Animated.View\n {...remainingProps}\n onLayout={onRowLayout}\n style={[styles.container, containerStyle]}>\n {leftElement()}\n {rightElement()}\n <GestureDetector gesture={tapGesture} touchAction=\"pan-y\">\n <Animated.View style={[animatedStyle, childrenContainerStyle]}>\n {children}\n </Animated.View>\n </GestureDetector>\n </Animated.View>\n </GestureDetector>\n );\n\n return testID ? (\n <View testID={testID}>{swipeableComponent}</View>\n ) : (\n swipeableComponent\n );\n }\n);\n\nexport default Swipeable;\nexport type SwipeableRef = ForwardedRef<SwipeableMethods>;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n leftActions: {\n ...StyleSheet.absoluteFillObject,\n flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',\n overflow: 'hidden',\n },\n rightActions: {\n ...StyleSheet.absoluteFillObject,\n flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',\n overflow: 'hidden',\n },\n});\n"]}
|
@@ -29,19 +29,30 @@ function createNativeWrapper(Component, config = {}) {
|
|
29
29
|
|
30
30
|
const ComponentWrapper = /*#__PURE__*/React.forwardRef((props, ref) => {
|
31
31
|
// Filter out props that should be passed to gesture handler wrapper
|
32
|
-
const
|
32
|
+
const {
|
33
|
+
gestureHandlerProps,
|
34
|
+
childProps
|
35
|
+
} = Object.keys(props).reduce((res, key) => {
|
33
36
|
// TS being overly protective with it's types, see https://github.com/microsoft/TypeScript/issues/26255#issuecomment-458013731 for more info
|
34
37
|
const allowedKeys = NATIVE_WRAPPER_PROPS_FILTER;
|
35
38
|
|
36
39
|
if (allowedKeys.includes(key)) {
|
37
40
|
// @ts-ignore FIXME(TS)
|
38
|
-
res[key] = props[key];
|
41
|
+
res.gestureHandlerProps[key] = props[key];
|
42
|
+
} else {
|
43
|
+
// @ts-ignore FIXME(TS)
|
44
|
+
res.childProps[key] = props[key];
|
39
45
|
}
|
40
46
|
|
41
47
|
return res;
|
42
|
-
}, {
|
43
|
-
|
44
|
-
|
48
|
+
}, {
|
49
|
+
gestureHandlerProps: { ...config
|
50
|
+
},
|
51
|
+
// Watch out not to modify config
|
52
|
+
childProps: {
|
53
|
+
enabled: props.enabled
|
54
|
+
}
|
55
|
+
});
|
45
56
|
|
46
57
|
const _ref = (0, React.useRef)();
|
47
58
|
|
@@ -62,7 +73,7 @@ function createNativeWrapper(Component, config = {}) {
|
|
62
73
|
return /*#__PURE__*/React.createElement(_NativeViewGestureHandler.NativeViewGestureHandler, _extends({}, gestureHandlerProps, {
|
63
74
|
// @ts-ignore TODO(TS)
|
64
75
|
ref: _gestureHandlerRef
|
65
|
-
}), /*#__PURE__*/React.createElement(Component, _extends({},
|
76
|
+
}), /*#__PURE__*/React.createElement(Component, _extends({}, childProps, {
|
66
77
|
ref: _ref
|
67
78
|
})));
|
68
79
|
}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["createNativeWrapper.tsx"],"names":["NATIVE_WRAPPER_PROPS_FILTER","nativeViewProps","createNativeWrapper","Component","config","ComponentWrapper","React","forwardRef","props","ref","gestureHandlerProps","Object","keys","reduce","res","key","allowedKeys","includes","_ref","_gestureHandlerRef","node","current","handlerTag","displayName","render","name"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,2BAA2B,GAAG,CAClC,GAAGC,yCAD+B,EAElC,uBAFkC,EAGlC,6BAHkC,CAApC;;AAMe,SAASC,mBAAT,CACbC,SADa,EAEbC,MAA+C,GAAG,EAFrC,EAGb;AAAA;;AACA,QAAMC,gBAAgB,gBAAGC,KAAK,CAACC,UAAN,CAGvB,CAACC,KAAD,EAAQC,GAAR,KAAgB;AAChB;AACA,
|
1
|
+
{"version":3,"sources":["createNativeWrapper.tsx"],"names":["NATIVE_WRAPPER_PROPS_FILTER","nativeViewProps","createNativeWrapper","Component","config","ComponentWrapper","React","forwardRef","props","ref","gestureHandlerProps","childProps","Object","keys","reduce","res","key","allowedKeys","includes","enabled","_ref","_gestureHandlerRef","node","current","handlerTag","displayName","render","name"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,2BAA2B,GAAG,CAClC,GAAGC,yCAD+B,EAElC,uBAFkC,EAGlC,6BAHkC,CAApC;;AAMe,SAASC,mBAAT,CACbC,SADa,EAEbC,MAA+C,GAAG,EAFrC,EAGb;AAAA;;AACA,QAAMC,gBAAgB,gBAAGC,KAAK,CAACC,UAAN,CAGvB,CAACC,KAAD,EAAQC,GAAR,KAAgB;AAChB;AACA,UAAM;AAAEC,MAAAA,mBAAF;AAAuBC,MAAAA;AAAvB,QAAsCC,MAAM,CAACC,IAAP,CAAYL,KAAZ,EAAmBM,MAAnB,CAC1C,CAACC,GAAD,EAAMC,GAAN,KAAc;AACZ;AACA,YAAMC,WAA8B,GAAGjB,2BAAvC;;AACA,UAAIiB,WAAW,CAACC,QAAZ,CAAqB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AArB,IAAiCA,SAHlC,IAIA,kBALF;AAOA,SAAOE,gBAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { useImperativeHandle, useRef } from 'react';\n\nimport {\n NativeViewGestureHandler,\n NativeViewGestureHandlerProps,\n nativeViewProps,\n} from './NativeViewGestureHandler';\n\n/*\n * This array should consist of:\n * - All keys in propTypes from NativeGestureHandler\n * (and all keys in GestureHandlerPropTypes)\n * - 'onGestureHandlerEvent'\n * - 'onGestureHandlerStateChange'\n */\nconst NATIVE_WRAPPER_PROPS_FILTER = [\n ...nativeViewProps,\n 'onGestureHandlerEvent',\n 'onGestureHandlerStateChange',\n] as const;\n\nexport default function createNativeWrapper<P>(\n Component: React.ComponentType<P>,\n config: Readonly<NativeViewGestureHandlerProps> = {}\n) {\n const ComponentWrapper = React.forwardRef<\n React.ComponentType<any>,\n P & NativeViewGestureHandlerProps\n >((props, ref) => {\n // Filter out props that should be passed to gesture handler wrapper\n const { gestureHandlerProps, childProps } = Object.keys(props).reduce(\n (res, key) => {\n // TS being overly protective with it's types, see https://github.com/microsoft/TypeScript/issues/26255#issuecomment-458013731 for more info\n const allowedKeys: readonly string[] = NATIVE_WRAPPER_PROPS_FILTER;\n if (allowedKeys.includes(key)) {\n // @ts-ignore FIXME(TS)\n res.gestureHandlerProps[key] = props[key];\n } else {\n // @ts-ignore FIXME(TS)\n res.childProps[key] = props[key];\n }\n return res;\n },\n {\n gestureHandlerProps: { ...config }, // Watch out not to modify config\n childProps: { enabled: props.enabled } as P,\n }\n );\n const _ref = useRef<React.ComponentType<P>>();\n const _gestureHandlerRef = useRef<React.ComponentType<P>>();\n useImperativeHandle(\n ref,\n // @ts-ignore TODO(TS) decide how nulls work in this context\n () => {\n const node = _gestureHandlerRef.current;\n // Add handlerTag for relations config\n if (_ref.current && node) {\n // @ts-ignore FIXME(TS) think about createHandler return type\n _ref.current.handlerTag = node.handlerTag;\n return _ref.current;\n }\n return null;\n },\n [_ref, _gestureHandlerRef]\n );\n return (\n <NativeViewGestureHandler\n {...gestureHandlerProps}\n // @ts-ignore TODO(TS)\n ref={_gestureHandlerRef}>\n <Component {...childProps} ref={_ref} />\n </NativeViewGestureHandler>\n );\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n ComponentWrapper.displayName =\n Component?.displayName ||\n // @ts-ignore if render doesn't exist it will return undefined and go further\n Component?.render?.name ||\n (typeof Component === 'string' && Component) ||\n 'ComponentWrapper';\n\n return ComponentWrapper;\n}\n"]}
|