@@ -3,18 +3,26 @@ import { Animated, StyleSheet, View, Text, I18nManager, StyleProp, ViewStyle, Di
33import { RectButton } from 'react-native-gesture-handler' ;
44import Swipeable from 'react-native-gesture-handler/Swipeable' ;
55
6+ export interface Column {
7+ /** 显示文字 */
8+ text : string ;
9+ /** 背景色 */
10+ color : string ;
11+ /** 滑动距离多少出现 */
12+ x ?: number ;
13+ /** 点击元素触发 */
14+ onPress ?: ( ) => void ;
15+ /** 宽度 */
16+ width ?: number | string ;
17+ /** 自定义元素 */
18+ render ?: ( text : string , record : Column , index : number ) => React . ReactNode ;
19+ }
20+
621export interface SwipeActionProps {
7- right ?: Array < {
8- text : string ;
9- color : string ;
10- x ?: number ;
11- onPress ?: ( ) => void ;
12- } > ;
13- left ?: Array < {
14- text : string ;
15- color : string ;
16- onPress ?: ( ) => void ;
17- } > ;
22+ /** 右边滑动出来的元素 */
23+ right ?: Array < Column > ;
24+ /** 左边滑动出来的元素 */
25+ left ?: Array < Column > ;
1826 swipeWidth ?: string | number ;
1927 enableTrackpadTwoFingerGesture ?: boolean ;
2028 friction ?: number ;
@@ -55,26 +63,27 @@ const SwipeAction = (props: SwipeActionProps, ref: any) => {
5563 return (
5664 right &&
5765 right . length > 0 &&
58- right . map ( ( { x = 1 , text, color, onPress } , idx ) => {
66+ right . map ( ( { x = 1 , text, color, onPress, width = '20%' , render } , idx ) => {
5967 const trans = progress . interpolate ( {
6068 inputRange : [ 0 , 1 ] ,
6169 outputRange : [ x , 0 ] ,
6270 } ) ;
6371 return (
6472 < View
73+ key = { idx }
6574 style = { {
66- width : swipeWidth ,
75+ width : width ,
6776 flexDirection : I18nManager . isRTL ? 'row-reverse' : 'row' ,
6877 } }
6978 >
70- < Animated . View style = { { flex : 1 , transform : [ { translateX : trans } ] } } key = { idx } >
79+ < Animated . View style = { { flex : 1 , transform : [ { translateX : trans } ] } } >
7180 < RectButton
7281 style = { [ styles . rightAction , { backgroundColor : color } ] }
7382 onPress = { ( ) => {
7483 onPress && onPress ( ) ;
7584 } }
7685 >
77- < Text style = { styles . actionText } > { text } </ Text >
86+ { render ? render ( text , right [ idx ] , idx ) : < Text style = { styles . actionText } > { text } </ Text > }
7887 </ RectButton >
7988 </ Animated . View >
8089 </ View >
@@ -87,7 +96,7 @@ const SwipeAction = (props: SwipeActionProps, ref: any) => {
8796 return (
8897 left &&
8998 left . length > 0 &&
90- left . map ( ( { text, color, onPress } , idx ) => {
99+ left . map ( ( { text, color, onPress, width , render } , idx ) => {
91100 const trans = dragX . interpolate ( {
92101 inputRange : [ 0 , 50 , 100 , 101 ] ,
93102 outputRange : [ - 20 , 0 , 0 , 1 ] ,
@@ -99,15 +108,16 @@ const SwipeAction = (props: SwipeActionProps, ref: any) => {
99108 width : swipeWidth ,
100109 flexDirection : I18nManager . isRTL ? 'row-reverse' : 'row' ,
101110 } }
111+ key = { idx }
102112 >
103- < Animated . View style = { { flex : 1 , transform : [ { translateX : trans } ] } } key = { idx } >
113+ < Animated . View style = { { flex : 1 , transform : [ { translateX : trans } ] } } >
104114 < RectButton
105115 style = { [ styles . rightAction , { backgroundColor : color } ] }
106116 onPress = { ( ) => {
107117 onPress && onPress ( ) ;
108118 } }
109119 >
110- < Text style = { styles . actionText } > { text } </ Text >
120+ { render ? render ( text , left [ idx ] , idx ) : < Text style = { styles . actionText } > { text } </ Text > }
111121 </ RectButton >
112122 </ Animated . View >
113123 </ View >
0 commit comments