@@ -19,123 +19,118 @@ import I18n from '../../../i18n';
1919export interface IDeleteActionProps {
2020 transX : SharedValue < number > ;
2121 width : number ;
22- rowHeight : number ;
2322 actionWidth : number ;
2423 longSwipe : number ;
2524 onDeletePress ( ) : void ;
2625 testID ?: string ;
2726}
2827
29- const SERVER_ITEM_PADDING_VERTICAL = 12 ;
28+ export const DeleteAction = memo ( ( { transX, width, actionWidth, longSwipe, onDeletePress, testID } : IDeleteActionProps ) => {
29+ const { colors } = useTheme ( ) ;
3030
31- export const DeleteAction = memo (
32- ( { transX, width, rowHeight, actionWidth, longSwipe, onDeletePress, testID } : IDeleteActionProps ) => {
33- const { colors } = useTheme ( ) ;
31+ const translateXDelete = useSharedValue ( 0 ) ;
3432
35- const translateXDelete = useSharedValue ( 0 ) ;
33+ const triggerDeleteAnimation = ( toValue : number ) => {
34+ Haptics . impactAsync ( Haptics . ImpactFeedbackStyle . Light ) . catch ( ( ) => { } ) ;
35+ translateXDelete . value = withSpring ( toValue , { overshootClamping : true , mass : 0.7 } ) ;
36+ } ;
3637
37- const triggerDeleteAnimation = ( toValue : number ) => {
38- Haptics . impactAsync ( Haptics . ImpactFeedbackStyle . Light ) ;
39- translateXDelete . value = withSpring ( toValue , { overshootClamping : true , mass : 0.7 } ) ;
40- } ;
41-
42- useAnimatedReaction (
43- ( ) => transX . value ,
44- ( currentTransX , previousTransX ) => {
45- if ( I18n . isRTL ) {
46- if ( previousTransX && currentTransX > longSwipe && previousTransX <= longSwipe ) {
47- scheduleOnRN ( triggerDeleteAnimation , actionWidth ) ;
48- } else if ( previousTransX && currentTransX <= longSwipe && previousTransX > longSwipe ) {
49- scheduleOnRN ( triggerDeleteAnimation , 0 ) ;
50- }
51- } else if ( previousTransX && currentTransX < - longSwipe && previousTransX >= - longSwipe ) {
52- scheduleOnRN ( triggerDeleteAnimation , - actionWidth ) ;
53- } else if ( previousTransX && currentTransX >= - longSwipe && previousTransX < - longSwipe ) {
38+ useAnimatedReaction (
39+ ( ) => transX . value ,
40+ ( currentTransX , previousTransX ) => {
41+ if ( I18n . isRTL ) {
42+ if ( previousTransX && currentTransX > longSwipe && previousTransX <= longSwipe ) {
43+ scheduleOnRN ( triggerDeleteAnimation , actionWidth ) ;
44+ } else if ( previousTransX && currentTransX <= longSwipe && previousTransX > longSwipe ) {
5445 scheduleOnRN ( triggerDeleteAnimation , 0 ) ;
5546 }
47+ } else if ( previousTransX && currentTransX < - longSwipe && previousTransX >= - longSwipe ) {
48+ scheduleOnRN ( triggerDeleteAnimation , - actionWidth ) ;
49+ } else if ( previousTransX && currentTransX >= - longSwipe && previousTransX < - longSwipe ) {
50+ scheduleOnRN ( triggerDeleteAnimation , 0 ) ;
5651 }
57- ) ;
52+ }
53+ ) ;
5854
59- const animatedDeleteButtonStyles = useAnimatedStyle ( ( ) => {
60- if ( I18n . isRTL ) {
61- // RTL: delete button appears from the left when swiping right
62- if ( transX . value > longSwipe && transX . value >= 2 * actionWidth ) {
63- const parallaxSwipe = interpolate (
64- transX . value ,
65- [ 2 * actionWidth , longSwipe ] ,
66- [ - actionWidth , - actionWidth - 0.1 * transX . value ]
67- ) ;
68- return {
69- transform : [ { translateX : parallaxSwipe - translateXDelete . value } ] ,
70- left : 0 ,
71- right : undefined
72- } ;
73- }
74- return {
75- transform : [ { translateX : transX . value - actionWidth - translateXDelete . value } ] ,
76- left : 0 ,
77- right : undefined
78- } ;
79- }
80- // LTR: delete button appears from the right when swiping left
81- if ( transX . value < - longSwipe && transX . value <= - 2 * actionWidth ) {
55+ const animatedDeleteButtonStyles = useAnimatedStyle ( ( ) => {
56+ if ( I18n . isRTL ) {
57+ // RTL: delete button appears from the left when swiping right
58+ if ( transX . value > longSwipe && transX . value >= 2 * actionWidth ) {
8259 const parallaxSwipe = interpolate (
8360 transX . value ,
84- [ - 2 * actionWidth , - longSwipe ] ,
85- [ actionWidth , actionWidth + 0.1 * transX . value ]
61+ [ 2 * actionWidth , longSwipe ] ,
62+ [ - actionWidth , - actionWidth - 0.1 * transX . value ]
8663 ) ;
8764 return {
88- transform : [ { translateX : parallaxSwipe + translateXDelete . value } ] ,
89- right : 0 ,
90- left : undefined
65+ transform : [ { translateX : parallaxSwipe - translateXDelete . value } ] ,
66+ left : 0 ,
67+ right : undefined
9168 } ;
9269 }
9370 return {
94- transform : [ { translateX : transX . value + actionWidth + translateXDelete . value } ] ,
71+ transform : [ { translateX : transX . value - actionWidth - translateXDelete . value } ] ,
72+ left : 0 ,
73+ right : undefined
74+ } ;
75+ }
76+ // LTR: delete button appears from the right when swiping left
77+ if ( transX . value < - longSwipe && transX . value <= - 2 * actionWidth ) {
78+ const parallaxSwipe = interpolate (
79+ transX . value ,
80+ [ - 2 * actionWidth , - longSwipe ] ,
81+ [ actionWidth , actionWidth + 0.1 * transX . value ]
82+ ) ;
83+ return {
84+ transform : [ { translateX : parallaxSwipe + translateXDelete . value } ] ,
9585 right : 0 ,
9686 left : undefined
9787 } ;
98- } ) ;
99- const viewHeight = { height : rowHeight + SERVER_ITEM_PADDING_VERTICAL } ;
100-
101- return (
102- < View
103- style = { [ styles . actionsLeftContainer , viewHeight , { backgroundColor : colors . buttonBackgroundDangerDefault } ] }
104- pointerEvents = 'box-none' >
105- < Animated . View
106- style = { [
107- styles . actionRightButtonContainer ,
108- {
109- width
110- } ,
111- viewHeight ,
112- animatedDeleteButtonStyles
113- ] } >
114- < RectButton
115- accessible
116- accessibilityLabel = { I18n . t ( 'Delete' ) }
117- testID = { testID }
118- style = { [ styles . actionButton , { backgroundColor : colors . buttonBackgroundDangerDefault } ] }
119- onPress = { onDeletePress } >
120- < CustomIcon size = { 24 } name = 'delete' color = { colors . fontWhite } />
121- </ RectButton >
122- </ Animated . View >
123- </ View >
124- ) ;
125- }
126- ) ;
88+ }
89+ return {
90+ transform : [ { translateX : transX . value + actionWidth + translateXDelete . value } ] ,
91+ right : 0 ,
92+ left : undefined
93+ } ;
94+ } ) ;
95+ return (
96+ < View
97+ style = { [ styles . actionsLeftContainer , { backgroundColor : colors . buttonBackgroundDangerDefault } ] }
98+ pointerEvents = 'box-none' >
99+ < Animated . View
100+ style = { [
101+ styles . actionRightButtonContainer ,
102+ {
103+ width
104+ } ,
105+ animatedDeleteButtonStyles
106+ ] } >
107+ < RectButton
108+ accessible
109+ accessibilityLabel = { I18n . t ( 'Delete' ) }
110+ testID = { testID }
111+ style = { [ styles . actionButton , { backgroundColor : colors . buttonBackgroundDangerDefault } ] }
112+ onPress = { onDeletePress } >
113+ < CustomIcon size = { 24 } name = 'delete' color = { colors . fontWhite } />
114+ </ RectButton >
115+ </ Animated . View >
116+ </ View >
117+ ) ;
118+ } ) ;
127119
128120const styles = StyleSheet . create ( {
129121 actionsLeftContainer : {
130122 flexDirection : 'row' ,
131123 position : 'absolute' ,
124+ top : 0 ,
125+ bottom : 0 ,
132126 left : 0 ,
133127 right : 0
134128 } ,
135129 actionRightButtonContainer : {
136130 position : 'absolute' ,
137131 justifyContent : 'center' ,
138132 top : 0 ,
133+ bottom : 0 ,
139134 alignItems : 'flex-end'
140135 } ,
141136 actionButton : {
0 commit comments