@hero-design/rn 8.5.0-alpha.0 → 8.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -66
- package/.turbo/turbo-publish:npm.log +0 -0
- package/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/es/index.js +641 -719
- package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
- package/lib/index.js +641 -718
- package/package.json +7 -5
- package/rollup.config.js +1 -0
- package/src/components/Icon/HeroIcon/glyphMap.json +1 -1
- package/src/components/Icon/IconList.ts +1 -0
- package/src/components/Swipeable/StyledSwipeable.tsx +2 -14
- package/src/components/Swipeable/SwipeableAction.tsx +7 -15
- package/src/components/Swipeable/index.tsx +136 -531
- package/src/components/SwipeableV2/StyledSwipeable.tsx +14 -0
- package/src/components/SwipeableV2/__tests__/__snapshots__/index.spec.tsx.snap +161 -0
- package/src/components/SwipeableV2/__tests__/index.spec.tsx +48 -0
- package/src/components/SwipeableV2/index.tsx +364 -0
- package/src/index.ts +2 -0
- package/types/components/Icon/IconList.d.ts +1 -1
- package/types/components/Icon/index.d.ts +1 -1
- package/types/components/Icon/utils.d.ts +1 -1
- package/types/components/Select/BaseOptionList.d.ts +4 -8
- package/types/components/Select/MultiSelect/OptionList.d.ts +4 -7
- package/types/components/Select/SingleSelect/OptionList.d.ts +4 -4
- package/types/components/Select/SingleSelect/StyledSingleSelect.d.ts +1 -1
- package/types/components/Swipeable/StyledSwipeable.d.ts +2 -15
- package/types/components/Swipeable/SwipeableAction.d.ts +6 -10
- package/types/components/Swipeable/index.d.ts +41 -24
- package/types/components/SwipeableV2/StyledSwipeable.d.ts +15 -0
- package/types/components/SwipeableV2/index.d.ts +46 -0
- package/types/components/Toolbar/index.d.ts +3 -2
- package/types/index.d.ts +2 -1
- package/src/components/Swipeable/Buttons.tsx +0 -65
- package/types/components/Swipeable/Buttons.d.ts +0 -15
|
@@ -1,555 +1,160 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentProps,
|
|
3
|
+
ReactNode,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { Animated, useWindowDimensions } from 'react-native';
|
|
2
9
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
PanResponderGestureState,
|
|
8
|
-
StyleProp,
|
|
9
|
-
StyleSheet,
|
|
10
|
-
ViewStyle,
|
|
11
|
-
} from 'react-native';
|
|
12
|
-
import { noop } from '../../utils/functions';
|
|
13
|
-
import { scale } from '../../utils/scale';
|
|
14
|
-
import Buttons from './Buttons';
|
|
15
|
-
import { StyledContent, StyledWrapper } from './StyledSwipeable';
|
|
10
|
+
Swipeable as RnghSwipeable,
|
|
11
|
+
GestureHandlerRootView,
|
|
12
|
+
RectButton,
|
|
13
|
+
} from 'react-native-gesture-handler';
|
|
16
14
|
import SwipeableAction from './SwipeableAction';
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
type State = 'closed' | 'leftOpen' | 'rightOpen';
|
|
17
|
+
// We are supporting both v1 and v2 of RNGH at the same time.
|
|
18
|
+
// SwipeableProps is only exported in v2, so we have to use ComponentProps.
|
|
19
|
+
type RnghSwipeableProps = ComponentProps<typeof RnghSwipeable>;
|
|
20
|
+
export interface SwipeableProps
|
|
21
|
+
extends Pick<
|
|
22
|
+
RnghSwipeableProps,
|
|
23
|
+
| 'enableTrackpadTwoFingerGesture'
|
|
24
|
+
| 'friction'
|
|
25
|
+
| 'leftThreshold'
|
|
26
|
+
| 'rightThreshold'
|
|
27
|
+
| 'overshootLeft'
|
|
28
|
+
| 'overshootRight'
|
|
29
|
+
| 'overshootFriction'
|
|
30
|
+
| 'useNativeAnimations'
|
|
31
|
+
| 'containerStyle'
|
|
32
|
+
| 'childrenContainerStyle'
|
|
33
|
+
> {
|
|
34
|
+
/**
|
|
35
|
+
* React node that is swipeable.
|
|
36
|
+
*/
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* State of the component.
|
|
40
|
+
*/
|
|
41
|
+
state?: 'closed' | 'leftOpen' | 'rightOpen';
|
|
42
|
+
/**
|
|
43
|
+
* Callback when the state of the component changes.
|
|
44
|
+
*/
|
|
45
|
+
onStateChange?: (state: State) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Action panel that is going to be revealed from the left side when user swipes right.
|
|
48
|
+
*/
|
|
49
|
+
leftActions?: ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* Width of the left action panel.
|
|
52
|
+
* By default, it will take up the whole width of the device.
|
|
53
|
+
*/
|
|
38
54
|
leftActionsWidth?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Action panel that is going to be revealed from the right side when user swipes left.
|
|
57
|
+
*/
|
|
58
|
+
rightActions?: ReactNode;
|
|
59
|
+
/**
|
|
60
|
+
* Width of the right action panel.
|
|
61
|
+
* By default, it will take up the whole width of the device.
|
|
62
|
+
*/
|
|
39
63
|
rightActionsWidth?: number;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
leftButtonWidth?: number;
|
|
53
|
-
rightButtonWidth?: number;
|
|
54
|
-
|
|
55
|
-
swipeState?: SwipeState;
|
|
56
|
-
style?: StyleProp<ViewStyle>;
|
|
57
|
-
children: React.ReactNode;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
type State = {
|
|
61
|
-
pan: Animated.ValueXY;
|
|
62
|
-
lastOffset: { x: number; y: number };
|
|
63
|
-
leftActionActivated: boolean;
|
|
64
|
-
rightActionActivated: boolean;
|
|
65
|
-
swipeState: SwipeState;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const getReleaseAnimationConfig = (
|
|
69
|
-
swipeState: SwipeState,
|
|
70
|
-
props: {
|
|
71
|
-
totalLeftButtonsWidth: number;
|
|
72
|
-
totalRightButtonsWidth: number;
|
|
73
|
-
}
|
|
64
|
+
/**
|
|
65
|
+
* Testing ID of the component
|
|
66
|
+
*/
|
|
67
|
+
testID?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const renderActions = (
|
|
71
|
+
actions: ReactNode,
|
|
72
|
+
width: number,
|
|
73
|
+
progress: Animated.AnimatedInterpolation,
|
|
74
|
+
direction: 'left' | 'right'
|
|
74
75
|
) => {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
easing: Easing.elastic(0.5),
|
|
81
|
-
useNativeDriver: true,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (swipeState === 'leftOpen') {
|
|
85
|
-
return {
|
|
86
|
-
...swipeReleaseAnimationConfig,
|
|
87
|
-
toValue: {
|
|
88
|
-
x: totalLeftButtonsWidth,
|
|
89
|
-
y: 0,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (swipeState === 'rightOpen') {
|
|
95
|
-
return {
|
|
96
|
-
...swipeReleaseAnimationConfig,
|
|
97
|
-
toValue: {
|
|
98
|
-
x: totalRightButtonsWidth * -1,
|
|
99
|
-
y: 0,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return swipeReleaseAnimationConfig;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const getPos = ({
|
|
108
|
-
swipeState,
|
|
109
|
-
totalLeftButtonsWidth,
|
|
110
|
-
totalRightButtonsWidth,
|
|
111
|
-
}: {
|
|
112
|
-
swipeState: SwipeState;
|
|
113
|
-
totalLeftButtonsWidth: number;
|
|
114
|
-
totalRightButtonsWidth: number;
|
|
115
|
-
}) => {
|
|
116
|
-
if (swipeState === 'leftOpen') {
|
|
117
|
-
return {
|
|
118
|
-
x: totalLeftButtonsWidth,
|
|
119
|
-
y: 0,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (swipeState === 'rightOpen') {
|
|
124
|
-
return {
|
|
125
|
-
x: totalRightButtonsWidth * -1,
|
|
126
|
-
y: 0,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return { x: 0, y: 0 };
|
|
131
|
-
};
|
|
76
|
+
const trans = progress.interpolate({
|
|
77
|
+
inputRange: [0, 1],
|
|
78
|
+
outputRange: direction === 'left' ? [-width, 0] : [width, 0],
|
|
79
|
+
extrapolate: 'clamp',
|
|
80
|
+
});
|
|
132
81
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
unmountedRef: React.MutableRefObject<boolean>;
|
|
82
|
+
return (
|
|
83
|
+
<Animated.View
|
|
84
|
+
style={{
|
|
85
|
+
width,
|
|
86
|
+
flexDirection: 'row',
|
|
87
|
+
transform: [{ translateX: trans }],
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{actions}
|
|
91
|
+
</Animated.View>
|
|
92
|
+
);
|
|
145
93
|
};
|
|
146
94
|
|
|
147
95
|
const Swipeable = ({
|
|
148
96
|
children,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
onSwipeLeftStart = noop,
|
|
157
|
-
onSwipeLeftEnd = noop,
|
|
158
|
-
rightActionsWidth = scale(85),
|
|
159
|
-
rightButtonWidth = scale(85),
|
|
160
|
-
onSwipeRightStart = noop,
|
|
161
|
-
onSwipeRightEnd = noop,
|
|
162
|
-
swipeState = 'closed',
|
|
163
|
-
onStateChange = noop,
|
|
164
|
-
...rest
|
|
97
|
+
state,
|
|
98
|
+
onStateChange,
|
|
99
|
+
leftActions,
|
|
100
|
+
leftActionsWidth,
|
|
101
|
+
rightActions,
|
|
102
|
+
rightActionsWidth,
|
|
103
|
+
...swipeableProps
|
|
165
104
|
}: SwipeableProps) => {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
leftActions,
|
|
169
|
-
leftContent,
|
|
170
|
-
rightActions,
|
|
171
|
-
rightContent,
|
|
172
|
-
style,
|
|
173
|
-
leftActionsWidth,
|
|
174
|
-
leftButtonWidth,
|
|
175
|
-
onSwipeLeftStart,
|
|
176
|
-
onSwipeLeftEnd,
|
|
177
|
-
rightActionsWidth,
|
|
178
|
-
rightButtonWidth,
|
|
179
|
-
onSwipeRightStart,
|
|
180
|
-
onSwipeRightEnd,
|
|
181
|
-
swipeState,
|
|
182
|
-
onStateChange,
|
|
183
|
-
...rest,
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const unmountedRef = React.useRef(false);
|
|
187
|
-
useEffect(() => {
|
|
188
|
-
return () => {
|
|
189
|
-
unmountedRef.current = true;
|
|
190
|
-
};
|
|
191
|
-
}, []);
|
|
192
|
-
|
|
193
|
-
const totalLeftButtonsWidth = leftActions.length * leftButtonWidth;
|
|
194
|
-
const totalRightButtonsWidth = rightActions.length * rightButtonWidth;
|
|
105
|
+
const { width } = useWindowDimensions();
|
|
106
|
+
const swipeableRef = useRef<RnghSwipeable>(null);
|
|
195
107
|
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
108
|
+
const renderLeftActions = useCallback(
|
|
109
|
+
(progress: Animated.AnimatedInterpolation) =>
|
|
110
|
+
renderActions(leftActions, leftActionsWidth || width, progress, 'left'),
|
|
111
|
+
[leftActions, leftActionsWidth, width]
|
|
112
|
+
);
|
|
113
|
+
const renderRightActions = useCallback(
|
|
114
|
+
(progress: Animated.AnimatedInterpolation) =>
|
|
115
|
+
renderActions(
|
|
116
|
+
rightActions,
|
|
117
|
+
rightActionsWidth || width,
|
|
118
|
+
progress,
|
|
119
|
+
'right'
|
|
120
|
+
),
|
|
121
|
+
[rightActions, rightActionsWidth, width]
|
|
207
122
|
);
|
|
208
|
-
|
|
209
|
-
const [state, setState] = React.useState<State>({
|
|
210
|
-
pan: new Animated.ValueXY(
|
|
211
|
-
getPos({
|
|
212
|
-
swipeState,
|
|
213
|
-
totalLeftButtonsWidth,
|
|
214
|
-
totalRightButtonsWidth,
|
|
215
|
-
})
|
|
216
|
-
),
|
|
217
|
-
lastOffset: { x: 0, y: 0 },
|
|
218
|
-
leftActionActivated: false,
|
|
219
|
-
rightActionActivated: true,
|
|
220
|
-
swipeState: 'closed',
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
propsRef.current = {
|
|
224
|
-
...propsWithDefaultValue,
|
|
225
|
-
canSwipeLeft,
|
|
226
|
-
canSwipeRight,
|
|
227
|
-
totalLeftButtonsWidth,
|
|
228
|
-
totalRightButtonsWidth,
|
|
229
|
-
hasLeftButtons,
|
|
230
|
-
hasRightButtons,
|
|
231
|
-
unmountedRef,
|
|
232
|
-
};
|
|
233
123
|
|
|
234
124
|
useEffect(() => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
125
|
+
if (swipeableRef.current === null) return;
|
|
126
|
+
|
|
127
|
+
switch (state) {
|
|
128
|
+
case 'leftOpen':
|
|
129
|
+
swipeableRef.current.openLeft();
|
|
130
|
+
break;
|
|
131
|
+
case 'rightOpen':
|
|
132
|
+
swipeableRef.current.openRight();
|
|
133
|
+
break;
|
|
134
|
+
case 'closed':
|
|
135
|
+
swipeableRef.current.close();
|
|
136
|
+
break;
|
|
244
137
|
}
|
|
245
|
-
|
|
246
|
-
if (animation) {
|
|
247
|
-
animation.stop();
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
}, [swipeState]);
|
|
251
|
-
|
|
252
|
-
const transform = [
|
|
253
|
-
{
|
|
254
|
-
translateX: state.pan.x.interpolate({
|
|
255
|
-
inputRange: [canSwipeLeft ? -width : 0, canSwipeRight ? width : 0],
|
|
256
|
-
outputRange: [
|
|
257
|
-
canSwipeLeft ? -width + StyleSheet.hairlineWidth : 0,
|
|
258
|
-
canSwipeRight ? width - StyleSheet.hairlineWidth : 0,
|
|
259
|
-
],
|
|
260
|
-
extrapolate: 'clamp',
|
|
261
|
-
}),
|
|
262
|
-
},
|
|
263
|
-
];
|
|
264
|
-
|
|
265
|
-
const panResponder = React.useRef(
|
|
266
|
-
PanResponder.create({
|
|
267
|
-
onMoveShouldSetPanResponder: (
|
|
268
|
-
_: GestureResponderEvent,
|
|
269
|
-
gestureState: PanResponderGestureState
|
|
270
|
-
) => {
|
|
271
|
-
return Math.abs(gestureState.dx) > swipeStartMinDistance;
|
|
272
|
-
},
|
|
273
|
-
onMoveShouldSetPanResponderCapture: (
|
|
274
|
-
_: GestureResponderEvent,
|
|
275
|
-
gestureState: PanResponderGestureState
|
|
276
|
-
) => {
|
|
277
|
-
return Math.abs(gestureState.dx) > swipeStartMinDistance;
|
|
278
|
-
},
|
|
279
|
-
onPanResponderGrant: () => {
|
|
280
|
-
setState((prevState) => {
|
|
281
|
-
prevState.pan.setOffset(prevState.lastOffset);
|
|
282
|
-
return prevState;
|
|
283
|
-
});
|
|
284
|
-
},
|
|
285
|
-
onPanResponderMove: (event, gestureState) => {
|
|
286
|
-
setState((prevState) => {
|
|
287
|
-
return hanleOnPanResponderMove(
|
|
288
|
-
prevState,
|
|
289
|
-
propsRef.current,
|
|
290
|
-
event,
|
|
291
|
-
gestureState
|
|
292
|
-
);
|
|
293
|
-
});
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
onPanResponderRelease: (event, gestureState) => {
|
|
297
|
-
setState((prevState) => {
|
|
298
|
-
return hanleOnPanResponderEnd(
|
|
299
|
-
prevState,
|
|
300
|
-
propsRef.current,
|
|
301
|
-
event,
|
|
302
|
-
gestureState
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
},
|
|
306
|
-
onPanResponderTerminationRequest: () => {
|
|
307
|
-
return false;
|
|
308
|
-
},
|
|
309
|
-
onPanResponderTerminate: (event, gestureState) => {
|
|
310
|
-
setState((prevState) => {
|
|
311
|
-
return hanleOnPanResponderEnd(
|
|
312
|
-
prevState,
|
|
313
|
-
propsRef.current,
|
|
314
|
-
event,
|
|
315
|
-
gestureState
|
|
316
|
-
);
|
|
317
|
-
});
|
|
318
|
-
},
|
|
319
|
-
})
|
|
320
|
-
).current;
|
|
138
|
+
}, [state]);
|
|
321
139
|
|
|
322
140
|
return (
|
|
323
|
-
<
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
{
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
>
|
|
337
|
-
{canSwipeRight && (
|
|
338
|
-
<Animated.View style={[{ transform, marginLeft: -width, width }]}>
|
|
339
|
-
{leftContent || (
|
|
340
|
-
<Buttons
|
|
341
|
-
buttons={leftActions}
|
|
342
|
-
isLeftButtons
|
|
343
|
-
panAnimatedValue={state.pan}
|
|
344
|
-
width={width}
|
|
345
|
-
canSwipeLeft={canSwipeLeft}
|
|
346
|
-
canSwipeRight={canSwipeRight}
|
|
347
|
-
buttonWidth={leftButtonWidth}
|
|
348
|
-
/>
|
|
349
|
-
)}
|
|
350
|
-
</Animated.View>
|
|
351
|
-
)}
|
|
352
|
-
<StyledContent style={{ transform }}>{children}</StyledContent>
|
|
353
|
-
{canSwipeLeft && (
|
|
354
|
-
<Animated.View style={[{ transform, marginRight: -width, width }]}>
|
|
355
|
-
{rightContent || (
|
|
356
|
-
<Buttons
|
|
357
|
-
buttons={rightActions}
|
|
358
|
-
isLeftButtons={false}
|
|
359
|
-
panAnimatedValue={state.pan}
|
|
360
|
-
width={width}
|
|
361
|
-
canSwipeRight={canSwipeRight}
|
|
362
|
-
canSwipeLeft={canSwipeLeft}
|
|
363
|
-
buttonWidth={rightButtonWidth}
|
|
364
|
-
/>
|
|
365
|
-
)}
|
|
366
|
-
</Animated.View>
|
|
367
|
-
)}
|
|
368
|
-
</StyledWrapper>
|
|
141
|
+
<GestureHandlerRootView>
|
|
142
|
+
<RnghSwipeable
|
|
143
|
+
{...swipeableProps}
|
|
144
|
+
ref={swipeableRef}
|
|
145
|
+
{...(leftActions !== undefined && { renderLeftActions })}
|
|
146
|
+
{...(rightActions !== undefined && { renderRightActions })}
|
|
147
|
+
onSwipeableLeftOpen={() => onStateChange?.('leftOpen')}
|
|
148
|
+
onSwipeableRightOpen={() => onStateChange?.('rightOpen')}
|
|
149
|
+
onSwipeableClose={() => onStateChange?.('closed')}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
</RnghSwipeable>
|
|
153
|
+
</GestureHandlerRootView>
|
|
369
154
|
);
|
|
370
155
|
};
|
|
371
156
|
|
|
372
|
-
|
|
373
|
-
swipeState: SwipeState,
|
|
374
|
-
pan: Animated.ValueXY,
|
|
375
|
-
totalLeftButtonsWidth: number,
|
|
376
|
-
totalRightButtonsWidth: number
|
|
377
|
-
) => {
|
|
378
|
-
const animationConfig = getReleaseAnimationConfig(swipeState, {
|
|
379
|
-
totalLeftButtonsWidth,
|
|
380
|
-
totalRightButtonsWidth,
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
pan.flattenOffset();
|
|
384
|
-
|
|
385
|
-
return Animated.timing(pan, animationConfig);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
const hanleOnPanResponderEnd = (
|
|
389
|
-
state: State,
|
|
390
|
-
contextValues: ContextValues,
|
|
391
|
-
event: GestureResponderEvent,
|
|
392
|
-
gestureState: PanResponderGestureState
|
|
393
|
-
) => {
|
|
394
|
-
const {
|
|
395
|
-
totalLeftButtonsWidth,
|
|
396
|
-
totalRightButtonsWidth,
|
|
397
|
-
unmountedRef,
|
|
398
|
-
onSwipeLeftEnd,
|
|
399
|
-
onSwipeRightEnd,
|
|
400
|
-
onStateChange,
|
|
401
|
-
} = contextValues;
|
|
402
|
-
const { leftActionActivated, rightActionActivated, pan, swipeState } = state;
|
|
403
|
-
const animationConfig = getReleaseAnimationConfig(swipeState, {
|
|
404
|
-
totalLeftButtonsWidth,
|
|
405
|
-
totalRightButtonsWidth,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
animationToNewState(
|
|
409
|
-
swipeState,
|
|
410
|
-
pan,
|
|
411
|
-
totalLeftButtonsWidth,
|
|
412
|
-
totalRightButtonsWidth
|
|
413
|
-
).start(() => {
|
|
414
|
-
if (unmountedRef.current) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
if (leftActionActivated && onSwipeLeftEnd) {
|
|
419
|
-
onSwipeLeftEnd(event, gestureState);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
if (rightActionActivated && onSwipeRightEnd) {
|
|
423
|
-
onSwipeRightEnd(event, gestureState);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
onStateChange(swipeState);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
return {
|
|
430
|
-
...state,
|
|
431
|
-
lastOffset: {
|
|
432
|
-
x: animationConfig.toValue.x,
|
|
433
|
-
y: animationConfig.toValue.y,
|
|
434
|
-
},
|
|
435
|
-
leftActionActivated: false,
|
|
436
|
-
rightActionActivated: false,
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
const hanleOnPanResponderMove = (
|
|
441
|
-
state: State,
|
|
442
|
-
contextValues: ContextValues,
|
|
443
|
-
event: GestureResponderEvent,
|
|
444
|
-
gestureState: PanResponderGestureState
|
|
445
|
-
) => {
|
|
446
|
-
const {
|
|
447
|
-
leftActionsWidth,
|
|
448
|
-
rightActionsWidth,
|
|
449
|
-
onSwipeLeftStart,
|
|
450
|
-
onSwipeRightStart,
|
|
451
|
-
canSwipeRight,
|
|
452
|
-
canSwipeLeft,
|
|
453
|
-
hasLeftButtons,
|
|
454
|
-
hasRightButtons,
|
|
455
|
-
} = contextValues;
|
|
456
|
-
const { lastOffset, leftActionActivated, swipeState, rightActionActivated } =
|
|
457
|
-
state;
|
|
458
|
-
|
|
459
|
-
const { dx, vx } = gestureState;
|
|
460
|
-
const x = dx + lastOffset.x;
|
|
461
|
-
const isSwipingLeft = vx < 0;
|
|
462
|
-
const isSwipingRight = vx > 0;
|
|
463
|
-
|
|
464
|
-
const leftActionsActivated = swipeState === 'leftOpen';
|
|
465
|
-
const rightActionsActivated = swipeState === 'rightOpen';
|
|
466
|
-
let nextLeftActionActivated = leftActionActivated;
|
|
467
|
-
let nextLeftButtonsActivated = leftActionsActivated;
|
|
468
|
-
let nextRightActionActivated = rightActionActivated;
|
|
469
|
-
let nextRightButtonsActivated = rightActionsActivated;
|
|
470
|
-
|
|
471
|
-
Animated.event(
|
|
472
|
-
[
|
|
473
|
-
null,
|
|
474
|
-
{
|
|
475
|
-
dx: state.pan.x,
|
|
476
|
-
dy: state.pan.y,
|
|
477
|
-
},
|
|
478
|
-
],
|
|
479
|
-
{ useNativeDriver: false }
|
|
480
|
-
)(event, gestureState);
|
|
481
|
-
|
|
482
|
-
if (!leftActionActivated && canSwipeRight && x >= leftActionsWidth) {
|
|
483
|
-
nextLeftActionActivated = true;
|
|
484
|
-
onSwipeRightStart(event, gestureState);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
if (leftActionActivated && canSwipeRight && x < leftActionsWidth) {
|
|
488
|
-
nextLeftActionActivated = false;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (!rightActionActivated && canSwipeLeft && x <= -rightActionsWidth) {
|
|
492
|
-
nextRightActionActivated = true;
|
|
493
|
-
onSwipeLeftStart(event, gestureState);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
if (rightActionActivated && canSwipeLeft && x > -rightActionsWidth) {
|
|
497
|
-
nextRightActionActivated = false;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
!leftActionsActivated &&
|
|
502
|
-
hasLeftButtons &&
|
|
503
|
-
!isSwipingLeft &&
|
|
504
|
-
x >= leftActionsWidth
|
|
505
|
-
) {
|
|
506
|
-
nextLeftButtonsActivated = true;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
if (leftActionsActivated && hasLeftButtons && isSwipingLeft) {
|
|
510
|
-
nextLeftButtonsActivated = false;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
!rightActionsActivated &&
|
|
515
|
-
hasRightButtons &&
|
|
516
|
-
!isSwipingRight &&
|
|
517
|
-
x <= -rightActionsWidth
|
|
518
|
-
) {
|
|
519
|
-
nextRightButtonsActivated = true;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (rightActionsActivated && hasRightButtons && isSwipingRight) {
|
|
523
|
-
nextRightButtonsActivated = false;
|
|
524
|
-
}
|
|
525
|
-
const needsUpdate =
|
|
526
|
-
nextLeftActionActivated !== leftActionActivated ||
|
|
527
|
-
nextLeftButtonsActivated !== leftActionsActivated ||
|
|
528
|
-
nextRightActionActivated !== rightActionActivated ||
|
|
529
|
-
nextRightButtonsActivated !== rightActionsActivated;
|
|
530
|
-
|
|
531
|
-
if (needsUpdate) {
|
|
532
|
-
const nextSwipeState = ((): SwipeState => {
|
|
533
|
-
if (nextLeftButtonsActivated) {
|
|
534
|
-
return 'leftOpen';
|
|
535
|
-
} else if (nextRightButtonsActivated) {
|
|
536
|
-
return 'rightOpen';
|
|
537
|
-
} else {
|
|
538
|
-
return 'closed';
|
|
539
|
-
}
|
|
540
|
-
})();
|
|
541
|
-
|
|
542
|
-
return {
|
|
543
|
-
...state,
|
|
544
|
-
leftActionActivated: nextLeftActionActivated,
|
|
545
|
-
rightActionActivated: nextRightActionActivated,
|
|
546
|
-
swipeState: nextSwipeState,
|
|
547
|
-
};
|
|
548
|
-
} else {
|
|
549
|
-
return state;
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
export default Object.assign(React.memo(Swipeable), {
|
|
157
|
+
export default Object.assign(Swipeable, {
|
|
554
158
|
Action: SwipeableAction,
|
|
159
|
+
Content: RectButton,
|
|
555
160
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import styled from '@emotion/native';
|
|
2
|
+
import { Animated, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type ActionIntent = 'primary' | 'success' | 'danger';
|
|
5
|
+
|
|
6
|
+
const StyledWrapper = styled(View)(() => ({
|
|
7
|
+
flexDirection: 'row',
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const StyledContent = styled(Animated.View)(() => ({
|
|
11
|
+
flex: 1,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
export { StyledWrapper, StyledContent };
|