@momo-kits/swipe 0.77.5 → 0.77.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.tsx +25 -4
  2. package/package.json +1 -1
  3. package/types.ts +78 -2
package/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, {FC, forwardRef, useContext} from 'react';
2
- import {Dimensions, Animated, TouchableOpacity, View} from 'react-native';
2
+ import {Animated, Dimensions, TouchableHighlight, View} from 'react-native';
3
3
  import {Swipeable} from 'react-native-gesture-handler';
4
4
  import {ApplicationContext, Colors, Icon, Text} from '@momo-kits/foundation';
5
5
  import {SwipeAction, SwipeProps} from './types';
@@ -10,6 +10,7 @@ const ACTION_WIDTH = 56;
10
10
  const Swipe: FC<SwipeProps> = forwardRef(
11
11
  ({children, leftActions, rightActions, ...props}, ref) => {
12
12
  const {theme} = useContext(ApplicationContext);
13
+ const screenWidth = Dimensions.get('window').width;
13
14
 
14
15
  const renderActionItem = (
15
16
  action: SwipeAction,
@@ -43,7 +44,11 @@ const Swipe: FC<SwipeProps> = forwardRef(
43
44
  });
44
45
 
45
46
  return (
46
- <TouchableOpacity style={{zIndex: zIndex}} onPress={onPress}>
47
+ <TouchableHighlight
48
+ underlayColor={Colors.black_01}
49
+ activeOpacity={0.8}
50
+ style={{zIndex: zIndex}}
51
+ onPress={onPress}>
47
52
  <Animated.View
48
53
  style={[
49
54
  styles.action,
@@ -62,17 +67,33 @@ const Swipe: FC<SwipeProps> = forwardRef(
62
67
  {label}
63
68
  </Text>
64
69
  </Animated.View>
65
- </TouchableOpacity>
70
+ </TouchableHighlight>
66
71
  );
67
72
  };
68
73
 
69
74
  const renderActions = (
70
- actions: SwipeAction[] | undefined,
75
+ actions: SwipeAction[] = [],
71
76
  direction: 'left' | 'right',
72
77
  dragX: Animated.AnimatedInterpolation,
73
78
  ) => {
79
+ let overlayPosition: {[key: string]: number} = {left: 0};
80
+ if (direction === 'right') {
81
+ overlayPosition = {right: 0};
82
+ }
74
83
  return (
75
84
  <View style={styles.row}>
85
+ <View
86
+ style={[
87
+ {
88
+ width: screenWidth,
89
+ backgroundColor: theme.colors.background.surface,
90
+ height: '100%',
91
+ zIndex: -10,
92
+ position: 'absolute',
93
+ },
94
+ overlayPosition,
95
+ ]}
96
+ />
76
97
  {actions?.map((item, index) => {
77
98
  //maximum 3 actions
78
99
  if (index < 3) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/swipe",
3
- "version": "0.77.5",
3
+ "version": "0.77.7",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "dependencies": {},
package/types.ts CHANGED
@@ -1,23 +1,99 @@
1
- import {Ref, RefObject} from 'react';
1
+ import {Ref} from 'react';
2
2
  import {Swipeable} from 'react-native-gesture-handler';
3
3
 
4
+ /**
5
+ * Represents an action item in the Swipe component.
6
+ */
4
7
  export type SwipeAction = {
8
+ /**
9
+ * The text label for the action button. This label is typically displayed on the button itself.
10
+ */
5
11
  label: string;
12
+
13
+ /**
14
+ * The icon for the action button, providing a visual representation of the action.
15
+ */
6
16
  icon: string;
17
+
18
+ /**
19
+ * The function to be called when the action button is pressed.
20
+ */
7
21
  onPress: () => void;
22
+
23
+ /**
24
+ * Optional. The background color of the action button.
25
+ * If not provided, a default color is used.
26
+ */
8
27
  backgroundColor?: string;
9
28
  };
10
29
 
30
+ /**
31
+ * Properties for the Swipe component, which allows swipeable actions on an item.
32
+ */
11
33
  export type SwipeProps = {
34
+ /**
35
+ * Optional. An array of `SwipeAction` items representing the actions available
36
+ * on swiping to the left. Each action is rendered as a button on the swipeable surface.
37
+ */
12
38
  leftActions?: SwipeAction[];
39
+
40
+ /**
41
+ * Optional. An array of `SwipeAction` items representing the actions available
42
+ * on swiping to the right. Each action is rendered as a button on the swipeable surface.
43
+ */
13
44
  rightActions?: SwipeAction[];
45
+
46
+ /**
47
+ * Optional. A callback function triggered when the swipeable surface is
48
+ * fully opened on the left side.
49
+ */
14
50
  onSwipeableLeftOpen?: () => void;
51
+
52
+ /**
53
+ * Optional. A callback function triggered when the swipeable surface is
54
+ * fully opened on the right side.
55
+ */
15
56
  onSwipeableRightOpen?: () => void;
57
+
58
+ /**
59
+ * Optional. A callback function triggered when the swipeable surface is
60
+ * fully opened, either from the left or the right.
61
+ */
16
62
  onSwipeableOpen?: () => void;
63
+
64
+ /**
65
+ * Optional. A callback function triggered when the swipeable surface has
66
+ * returned to its original position and is closed.
67
+ */
17
68
  onSwipeableClose?: () => void;
69
+
70
+ /**
71
+ * Optional. A callback function triggered when the swipeable surface is
72
+ * about to open on the left side.
73
+ */
18
74
  onSwipeableLeftWillOpen?: () => void;
75
+
76
+ /**
77
+ * Optional. A callback function triggered when the swipeable surface is
78
+ * about to open on the right side.
79
+ */
19
80
  onSwipeableRightWillOpen?: () => void;
81
+
82
+ /**
83
+ * Optional. A callback function triggered when the swipeable surface is
84
+ * about to open, either from the left or the right.
85
+ */
20
86
  onSwipeableWillOpen?: () => void;
87
+
88
+ /**
89
+ * Optional. A callback function triggered when the swipeable surface is
90
+ * about to close and return to its original position.
91
+ */
21
92
  onSwipeableWillClose?: () => void;
22
- ref?: Ref<Swipeable>;
93
+
94
+ /**
95
+ * Optional. A ref for the underlying `Swipeable` component from `react-native-gesture-handler`.
96
+ * Can be used for manually triggering actions, like closing the swipeable surface.
97
+ */
98
+ ref?: React.ForwardedRef<Swipeable>;
23
99
  };