@momo-kits/swipe 0.73.3-beta.5 → 0.74.2-react-native.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/SwipeView.tsx ADDED
@@ -0,0 +1,144 @@
1
+ import React, {
2
+ forwardRef,
3
+ ForwardRefRenderFunction,
4
+ useContext,
5
+ useImperativeHandle,
6
+ useRef,
7
+ } from 'react';
8
+ import {Animated, Dimensions, TouchableHighlight, View} from 'react-native';
9
+ import {Swipeable} from 'react-native-gesture-handler';
10
+ import {ApplicationContext, Colors, Icon, Text} from '@momo-kits/foundation';
11
+ import {SwipeableRef, SwipeAction, SwipeProps} from './types';
12
+ import styles from './styles';
13
+
14
+ const ACTION_WIDTH = 56;
15
+
16
+ export const Swipe: ForwardRefRenderFunction<SwipeableRef, SwipeProps> = (
17
+ {children, leftActions, rightActions, ...props},
18
+ ref,
19
+ ) => {
20
+ const {theme} = useContext(ApplicationContext);
21
+ const screenWidth = Dimensions.get('window').width;
22
+ const swipeableRef = useRef<Swipeable>(null);
23
+
24
+ const renderActionItem = (
25
+ action: SwipeAction,
26
+ index: number,
27
+ length: number,
28
+ direction: 'left' | 'right',
29
+ dragX: Animated.AnimatedInterpolation,
30
+ ) => {
31
+ const {
32
+ label,
33
+ icon,
34
+ onPress,
35
+ backgroundColor = theme.colors.highlight.primary,
36
+ } = action;
37
+
38
+ let inputRange = [0, ACTION_WIDTH * length];
39
+ let outputRange = [-ACTION_WIDTH * (index + 1), 0];
40
+
41
+ let zIndex = -index;
42
+
43
+ if (direction === 'right') {
44
+ inputRange = [-ACTION_WIDTH * length, 0];
45
+ outputRange = [0, ACTION_WIDTH * (length - index)];
46
+ zIndex = index;
47
+ }
48
+
49
+ const translateX = dragX.interpolate({
50
+ inputRange,
51
+ outputRange,
52
+ extrapolate: 'clamp',
53
+ });
54
+
55
+ return (
56
+ <TouchableHighlight
57
+ underlayColor={Colors.black_01}
58
+ activeOpacity={0.8}
59
+ style={{zIndex: zIndex}}
60
+ onPress={onPress}>
61
+ <Animated.View
62
+ style={[
63
+ styles.action,
64
+ {
65
+ backgroundColor,
66
+ transform: [{translateX}],
67
+ width: ACTION_WIDTH,
68
+ },
69
+ ]}>
70
+ {!!icon && <Icon source={icon} color={Colors.black_01} />}
71
+ <Text
72
+ style={styles.textCenter}
73
+ numberOfLines={1}
74
+ color={Colors.black_01}
75
+ typography={'label_s_medium'}>
76
+ {label}
77
+ </Text>
78
+ </Animated.View>
79
+ </TouchableHighlight>
80
+ );
81
+ };
82
+
83
+ const renderActions = (
84
+ actions: SwipeAction[] = [],
85
+ direction: 'left' | 'right',
86
+ dragX: Animated.AnimatedInterpolation,
87
+ ) => {
88
+ let overlayPosition: {[key: string]: number} = {left: 0};
89
+ if (direction === 'right') {
90
+ overlayPosition = {right: 0};
91
+ }
92
+ return (
93
+ <View style={styles.row}>
94
+ <View
95
+ style={[
96
+ {
97
+ width: screenWidth,
98
+ backgroundColor: theme.colors.background.surface,
99
+ height: '100%',
100
+ zIndex: -10,
101
+ position: 'absolute',
102
+ },
103
+ overlayPosition,
104
+ ]}
105
+ />
106
+ {actions?.map((item, index) => {
107
+ //maximum 3 actions
108
+ if (index < 3) {
109
+ return renderActionItem(
110
+ item,
111
+ index,
112
+ actions?.length,
113
+ direction,
114
+ dragX,
115
+ );
116
+ }
117
+ })}
118
+ </View>
119
+ );
120
+ };
121
+
122
+ useImperativeHandle(ref, () => ({
123
+ openLeft: () => swipeableRef?.current?.openLeft(),
124
+ openRight: () => swipeableRef?.current?.openRight(),
125
+ close: () => swipeableRef?.current?.close(),
126
+ }));
127
+
128
+ return (
129
+ <Swipeable
130
+ {...props}
131
+ containerStyle={styles.container}
132
+ ref={swipeableRef}
133
+ renderRightActions={(progressAnimatedValue, dragAnimatedValue) =>
134
+ renderActions(rightActions, 'right', dragAnimatedValue)
135
+ }
136
+ renderLeftActions={(progressAnimatedValue, dragAnimatedValue) =>
137
+ renderActions(leftActions, 'left', dragAnimatedValue)
138
+ }>
139
+ {children}
140
+ </Swipeable>
141
+ );
142
+ };
143
+
144
+ export default forwardRef(Swipe);
package/index.tsx ADDED
@@ -0,0 +1,3 @@
1
+ import Swipe from "./SwipeView";
2
+
3
+ export {Swipe}
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@momo-kits/swipe",
3
- "version": "0.73.3-beta.5",
3
+ "version": "0.74.2-react-native.1",
4
4
  "private": false,
5
- "main": "index.js",
6
- "dependencies": {},
5
+ "main": "index.tsx",
7
6
  "peerDependencies": {
8
- "prop-types": "^15.7.2",
9
- "react": "^16.9.0",
10
- "react-native": ">=0.55",
11
- "@momo-kits/core-v2": ">=0.0.5-beta"
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "*",
9
+ "react-native": "*",
10
+ "prop-types": "15.7.2"
12
11
  },
13
- "devDependencies": {},
14
- "license": "MoMo"
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
+ },
15
+ "license": "MoMo",
16
+ "dependencies": {}
15
17
  }
package/publish.sh CHANGED
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- #curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/swipe new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/swipe"}'
29
+ ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/swipe new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/swipe"}'
package/styles.ts ADDED
@@ -0,0 +1,16 @@
1
+ import {StyleSheet} from 'react-native';
2
+
3
+ export default StyleSheet.create({
4
+ action: {
5
+ height: '100%',
6
+ alignItems: 'center',
7
+ justifyContent: 'center',
8
+ },
9
+ row: {
10
+ flexDirection: 'row',
11
+ },
12
+ textCenter: {
13
+ textAlign: 'center',
14
+ },
15
+ container: {width: '100%'},
16
+ });
package/types.ts ADDED
@@ -0,0 +1,99 @@
1
+ import {Ref} from 'react';
2
+ import {Swipeable} from 'react-native-gesture-handler';
3
+
4
+ /**
5
+ * Represents an action item in the Swipe component.
6
+ */
7
+ export type SwipeAction = {
8
+ /**
9
+ * The text label for the action button. This label is typically displayed on the button itself.
10
+ */
11
+ label: string;
12
+
13
+ /**
14
+ * The icon for the action button, providing a visual representation of the action.
15
+ */
16
+ icon: string;
17
+
18
+ /**
19
+ * The function to be called when the action button is pressed.
20
+ */
21
+ onPress: () => void;
22
+
23
+ /**
24
+ * Optional. The background color of the action button.
25
+ * If not provided, a default color is used.
26
+ */
27
+ backgroundColor?: string;
28
+ };
29
+
30
+ /**
31
+ * Properties for the Swipe component, which allows swipeable actions on an item.
32
+ */
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
+ */
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
+ */
44
+ rightActions?: SwipeAction[];
45
+
46
+ /**
47
+ * Optional. A callback function triggered when the swipeable surface is
48
+ * fully opened on the left side.
49
+ */
50
+ onSwipeableLeftOpen?: () => void;
51
+
52
+ /**
53
+ * Optional. A callback function triggered when the swipeable surface is
54
+ * fully opened on the right side.
55
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
92
+ onSwipeableWillClose?: () => void;
93
+ };
94
+
95
+ export type SwipeableRef = {
96
+ openLeft: () => void;
97
+ openRight: () => void;
98
+ close: () => void;
99
+ };