@momo-kits/swipe 0.77.2 → 0.77.4

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/index.tsx ADDED
@@ -0,0 +1,109 @@
1
+ import React, {FC, forwardRef, useContext} from 'react';
2
+ import {Dimensions, Animated, TouchableOpacity, View} from 'react-native';
3
+ import {Swipeable} from 'react-native-gesture-handler';
4
+ import {ApplicationContext, Colors, Icon, Text} from '@momo-kits/foundation';
5
+ import {SwipeAction, SwipeProps} from './types';
6
+ import styles from './styles';
7
+
8
+ const ACTION_WIDTH = 56;
9
+
10
+ const Swipe: FC<SwipeProps> = forwardRef(
11
+ ({children, leftActions, rightActions, ...props}, ref) => {
12
+ const {theme} = useContext(ApplicationContext);
13
+
14
+ const renderActionItem = (
15
+ action: SwipeAction,
16
+ index: number,
17
+ length: number,
18
+ direction: 'left' | 'right',
19
+ dragX: Animated.AnimatedInterpolation,
20
+ ) => {
21
+ const {
22
+ label,
23
+ icon,
24
+ onPress,
25
+ backgroundColor = theme.colors.highlight.primary,
26
+ } = action;
27
+
28
+ let inputRange = [0, ACTION_WIDTH * length];
29
+ let outputRange = [-ACTION_WIDTH * (index + 1), 0];
30
+
31
+ let zIndex = -index;
32
+
33
+ if (direction === 'right') {
34
+ inputRange = [-ACTION_WIDTH * length, 0];
35
+ outputRange = [0, ACTION_WIDTH * (length - index)];
36
+ zIndex = index;
37
+ }
38
+
39
+ const translateX = dragX.interpolate({
40
+ inputRange,
41
+ outputRange,
42
+ extrapolate: 'clamp',
43
+ });
44
+
45
+ return (
46
+ <TouchableOpacity style={{zIndex: zIndex}} onPress={onPress}>
47
+ <Animated.View
48
+ style={[
49
+ styles.action,
50
+ {
51
+ backgroundColor,
52
+ transform: [{translateX}],
53
+ width: ACTION_WIDTH,
54
+ },
55
+ ]}>
56
+ {!!icon && <Icon source={icon} color={Colors.black_01} />}
57
+ <Text
58
+ style={styles.textCenter}
59
+ numberOfLines={1}
60
+ color={Colors.black_01}
61
+ typography={'label_s'}>
62
+ {label}
63
+ </Text>
64
+ </Animated.View>
65
+ </TouchableOpacity>
66
+ );
67
+ };
68
+
69
+ const renderActions = (
70
+ actions: SwipeAction[] | undefined,
71
+ direction: 'left' | 'right',
72
+ dragX: Animated.AnimatedInterpolation,
73
+ ) => {
74
+ return (
75
+ <View style={styles.row}>
76
+ {actions?.map((item, index) => {
77
+ //maximum 3 actions
78
+ if (index < 3) {
79
+ return renderActionItem(
80
+ item,
81
+ index,
82
+ actions?.length,
83
+ direction,
84
+ dragX,
85
+ );
86
+ }
87
+ })}
88
+ </View>
89
+ );
90
+ };
91
+
92
+ return (
93
+ <Swipeable
94
+ {...props}
95
+ containerStyle={styles.container}
96
+ ref={ref}
97
+ renderRightActions={(progressAnimatedValue, dragAnimatedValue) =>
98
+ renderActions(rightActions, 'right', dragAnimatedValue)
99
+ }
100
+ renderLeftActions={(progressAnimatedValue, dragAnimatedValue) =>
101
+ renderActions(leftActions, 'left', dragAnimatedValue)
102
+ }>
103
+ {children}
104
+ </Swipeable>
105
+ );
106
+ },
107
+ );
108
+
109
+ export default Swipe;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@momo-kits/swipe",
3
- "version": "0.77.2",
3
+ "version": "0.77.4",
4
4
  "private": false,
5
- "main": "index.js",
5
+ "main": "index.tsx",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
+ "@momo-kits/foundation": "latest",
8
9
  "prop-types": "^15.7.2",
9
- "react": "^16.9.0",
10
- "react-native": ">=0.55",
11
- "@momo-kits/core-v2": ">=0.0.5-beta"
10
+ "react": "16.9.0",
11
+ "react-native": ">=0.55"
12
12
  },
13
13
  "devDependencies": {},
14
14
  "license": "MoMo"
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,23 @@
1
+ import {Ref, RefObject} from 'react';
2
+ import {Swipeable} from 'react-native-gesture-handler';
3
+
4
+ export type SwipeAction = {
5
+ label: string;
6
+ icon: string;
7
+ onPress: () => void;
8
+ backgroundColor?: string;
9
+ };
10
+
11
+ export type SwipeProps = {
12
+ leftActions?: SwipeAction[];
13
+ rightActions?: SwipeAction[];
14
+ onSwipeableLeftOpen?: () => void;
15
+ onSwipeableRightOpen?: () => void;
16
+ onSwipeableOpen?: () => void;
17
+ onSwipeableClose?: () => void;
18
+ onSwipeableLeftWillOpen?: () => void;
19
+ onSwipeableRightWillOpen?: () => void;
20
+ onSwipeableWillOpen?: () => void;
21
+ onSwipeableWillClose?: () => void;
22
+ ref?: Ref<Swipeable>;
23
+ };