@@ -102,8 +102,6 @@ export default class Swipeable extends Component<PropType, StateType> {
102
102
measureCompleted : false
103
103
} ;
104
104
105
- this . _updateAnimatedEvent ( props , this . state ) ;
106
-
107
105
this . _onGestureEvent = Animated . event ( [ { nativeEvent : { translationX : dragX } } ] , {
108
106
useNativeDriver : props . useNativeAnimations ,
109
107
listener : this . _handleDrag
@@ -112,7 +110,7 @@ export default class Swipeable extends Component<PropType, StateType> {
112
110
113
111
_handleDrag = ( e ) => {
114
112
const { onToggleSwipeLeft} = this . props ;
115
-
113
+
116
114
if ( onToggleSwipeLeft ) {
117
115
// Drag left toggle
118
116
const { rowWidth, leftWidth} = this . state ;
@@ -123,7 +121,7 @@ export default class Swipeable extends Component<PropType, StateType> {
123
121
// move item right
124
122
this . dragThresholdReached = true ;
125
123
onToggleSwipeLeft ( { rowWidth, leftWidth, dragX : x , triggerHaptic : true } ) ;
126
- }
124
+ }
127
125
if ( this . dragThresholdReached && x < threshold - 10 ) {
128
126
// move item left
129
127
this . dragThresholdReached = false ;
@@ -132,27 +130,12 @@ export default class Swipeable extends Component<PropType, StateType> {
132
130
}
133
131
}
134
132
135
- // TODO: change to componentDidUpdate
136
- UNSAFE_componentWillUpdate ( props : PropType , state : StateType ) {
137
- if (
138
- this . props . friction !== props . friction ||
139
- this . props . overshootLeft !== props . overshootLeft ||
140
- this . props . overshootRight !== props . overshootRight ||
141
- this . props . overshootFriction !== props . overshootFriction ||
142
- this . state . leftWidth !== state . leftWidth ||
143
- this . state . rightOffset !== state . rightOffset ||
144
- this . state . rowWidth !== state . rowWidth
145
- ) {
146
- this . _updateAnimatedEvent ( props , state ) ;
147
- }
148
- }
149
-
150
- _updateAnimatedEvent = ( props : PropType , state : StateType ) => {
151
- const { friction, overshootFriction} = props ;
152
- const { dragX, rowTranslation, leftWidth = 0 , rowWidth = 0 } = state ;
153
- const { rightOffset = rowWidth } = state ;
133
+ getTransX = ( ) => {
134
+ const { friction, overshootFriction} = this . props ;
135
+ const { dragX, rowTranslation, leftWidth = 0 , rowWidth = 0 } = this . state ;
136
+ const { rightOffset = rowWidth } = this . state ;
154
137
const rightWidth = Math . max ( 0 , rowWidth - rightOffset ) ;
155
- const { overshootLeft = leftWidth > 0 , overshootRight = rightWidth > 0 } = props ;
138
+ const { overshootLeft = leftWidth > 0 , overshootRight = rightWidth > 0 } = this . props ;
156
139
157
140
const transX = Animated . add (
158
141
rowTranslation ,
@@ -174,32 +157,63 @@ export default class Swipeable extends Component<PropType, StateType> {
174
157
leftWidth + ( overshootLeft || overshootFriction > 1 ? 1 : 0 )
175
158
] ,
176
159
} ) ;
177
- this . _transX = transX ;
178
- this . _showLeftAction =
179
- leftWidth > 0
180
- ? transX . interpolate ( {
160
+
161
+ return transX ;
162
+ }
163
+
164
+ getShowLeftAction = ( ) => {
165
+ const transX = this . getTransX ( ) ;
166
+ const { leftWidth = 0 } = this . state ;
167
+
168
+ const showLeftAction = leftWidth > 0 ?
169
+ transX . interpolate ( {
181
170
inputRange : [ - 1 , 0 , leftWidth ] ,
182
171
outputRange : [ 0 , 0 , 1 ]
183
172
} )
184
- : new Animated . Value ( 0 ) ;
185
- this . _leftActionTranslate = this . _showLeftAction . interpolate ( {
173
+ : new Animated . Value ( 0 ) ;
174
+
175
+ return showLeftAction ;
176
+ }
177
+
178
+ getLeftActionTranslate = ( ) => {
179
+ const showLeftAction = this . getShowLeftAction ( ) ;
180
+
181
+ const leftActionTranslate = showLeftAction . interpolate ( {
186
182
inputRange : [ 0 , Number . MIN_VALUE ] ,
187
183
outputRange : [ - 10000 , 0 ] ,
188
184
extrapolate : 'clamp'
189
185
} ) ;
190
- this . _showRightAction =
191
- rightWidth > 0
192
- ? transX . interpolate ( {
186
+
187
+ return leftActionTranslate ;
188
+ }
189
+
190
+ getShowRightAction = ( ) => {
191
+ const transX = this . getTransX ( ) ;
192
+ const { rowWidth = 0 } = this . state ;
193
+ const { rightOffset = rowWidth } = this . state ;
194
+ const rightWidth = Math . max ( 0 , rowWidth - rightOffset ) ;
195
+
196
+ const showRightAction = rightWidth > 0 ?
197
+ transX . interpolate ( {
193
198
inputRange : [ - rightWidth , 0 , 1 ] ,
194
199
outputRange : [ 1 , 0 , 0 ]
195
200
} )
196
- : new Animated . Value ( 0 ) ;
197
- this . _rightActionTranslate = this . _showRightAction . interpolate ( {
201
+ : new Animated . Value ( 0 ) ;
202
+
203
+ return showRightAction ;
204
+ }
205
+
206
+ getRightActionTranslate = ( ) => {
207
+ const showRightAction = this . getShowRightAction ( ) ;
208
+
209
+ const rightActionTranslate = showRightAction . interpolate ( {
198
210
inputRange : [ 0 , Number . MIN_VALUE ] ,
199
211
outputRange : [ - 10000 , 0 ] ,
200
212
extrapolate : 'clamp'
201
213
} ) ;
202
- } ;
214
+
215
+ return rightActionTranslate ;
216
+ }
203
217
204
218
_onTapHandlerStateChange = ( { nativeEvent} ) => {
205
219
if ( this . rowState !== 0 ) {
@@ -225,13 +239,13 @@ export default class Swipeable extends Component<PropType, StateType> {
225
239
const { rightOffset = rowWidth } = this . state ;
226
240
const rightWidth = rowWidth - rightOffset ;
227
241
const {
228
- fullSwipeLeft,
229
- fullSwipeRight,
230
- friction,
231
- leftThreshold = leftWidth / 2 ,
232
- rightThreshold = rightWidth / 2 ,
233
- fullLeftThreshold,
234
- fullRightThreshold,
242
+ fullSwipeLeft,
243
+ fullSwipeRight,
244
+ friction,
245
+ leftThreshold = leftWidth / 2 ,
246
+ rightThreshold = rightWidth / 2 ,
247
+ fullLeftThreshold,
248
+ fullRightThreshold,
235
249
onToggleSwipeLeft
236
250
} = this . props ;
237
251
const startOffsetX = this . _currentOffset ( ) + dragX / friction ;
@@ -291,7 +305,7 @@ export default class Swipeable extends Component<PropType, StateType> {
291
305
dragX . setValue ( 0 ) ;
292
306
rowTranslation . setValue ( fromValue ) ;
293
307
this . rowState = Math . sign ( toValue ) ;
294
-
308
+
295
309
Animated . spring ( rowTranslation , {
296
310
toValue,
297
311
restSpeedThreshold : 1.7 ,
@@ -301,7 +315,7 @@ export default class Swipeable extends Component<PropType, StateType> {
301
315
useNativeDriver : useNativeAnimations ,
302
316
...animationOptions
303
317
} ) . start ( ( { finished} ) => {
304
- if ( finished ) {
318
+ if ( finished ) {
305
319
if ( toValue === rowWidth && onFullSwipeLeft ) {
306
320
onFullSwipeLeft ( ) ;
307
321
} else if ( toValue === - rowWidth && onFullSwipeRight ) {
@@ -436,10 +450,10 @@ export default class Swipeable extends Component<PropType, StateType> {
436
450
style = { [
437
451
styles . leftActions ,
438
452
leftActionsContainerStyle ,
439
- { transform : [ { translateX : this . _leftActionTranslate } ] }
453
+ { transform : [ { translateX : this . getLeftActionTranslate ( ) } ] }
440
454
] }
441
455
>
442
- { renderLeftActions ( this . _showLeftAction , this . _transX ) }
456
+ { renderLeftActions ( this . getShowLeftAction ( ) , this . getTransX ( ) ) }
443
457
< View onLayout = { this . _onLeftLayout } />
444
458
</ Animated . View >
445
459
) ;
@@ -449,10 +463,10 @@ export default class Swipeable extends Component<PropType, StateType> {
449
463
style = { [
450
464
styles . rightActions ,
451
465
rightActionsContainerStyle ,
452
- { transform : [ { translateX : this . _rightActionTranslate } ] }
466
+ { transform : [ { translateX : this . getRightActionTranslate ( ) } ] }
453
467
] }
454
468
>
455
- { renderRightActions ( this . _showRightAction , this . _transX ) }
469
+ { renderRightActions ( this . getShowRightAction ( ) , this . getTransX ( ) ) }
456
470
< View onLayout = { this . _onRightLayout } />
457
471
</ Animated . View >
458
472
) ;
@@ -472,7 +486,7 @@ export default class Swipeable extends Component<PropType, StateType> {
472
486
< Animated . View
473
487
testID = { testID }
474
488
style = { [
475
- { transform : [ { translateX : this . _transX } ] } ,
489
+ { transform : [ { translateX : this . getTransX ( ) } ] } ,
476
490
childrenContainerStyle
477
491
] }
478
492
>
0 commit comments