@@ -162,12 +162,16 @@ open class SwipeableTableViewCell: UITableViewCell {
162
162
}
163
163
164
164
@objc private func handlePan( _ recognizer: UIPanGestureRecognizer ) {
165
- if recognizer. state == . ended {
165
+ switch recognizer. state {
166
+ case . ended, . cancelled:
166
167
startSlideAnimation ( recognizer)
168
+ default :
169
+ break
167
170
}
168
171
}
169
172
170
173
@objc private func handlePrimaryButtonTap( ) {
174
+ guard contentOffset. x >= Constants . disconnectPoint else { return }
171
175
onPrimaryButtonTap ? ( )
172
176
}
173
177
@@ -193,6 +197,7 @@ open class SwipeableTableViewCell: UITableViewCell {
193
197
self . scrollView. setContentOffset ( self . slideTargetPoint, animated: false )
194
198
} , completion: { _ in
195
199
self . buttonScaleAnimationIsRunning = false
200
+ self . updateSlideDestination ( )
196
201
displayLink? . invalidate ( )
197
202
}
198
203
)
@@ -215,12 +220,12 @@ open class SwipeableTableViewCell: UITableViewCell {
215
220
216
221
private func updateShape( ) {
217
222
guard slideDestination == . end else { return }
218
-
219
223
scrollViewContentView. move ( by: contentOffset. x)
220
-
221
224
button. stretch ( by: calulateCircleOffset ( for: contentOffset. x) )
222
225
button. imageView? . alpha = contentOffset. x > Constants . buttonDimension / 2 + Constants. primaryButtonTrailingOffset ? 1 : 0
223
- button. backgroundColor = contentOffset. x > Constants . disconnectPoint ? buttonActiveBackgroundColor : scrollViewContentView. backgroundColor
226
+ if !button. isHighlighted {
227
+ button. backgroundColor = contentOffset. x > Constants . disconnectPoint ? buttonActiveBackgroundColor : scrollViewContentView. backgroundColor
228
+ }
224
229
}
225
230
226
231
private func calulateCircleOffset( for x: CGFloat ) -> CGFloat {
@@ -230,7 +235,7 @@ open class SwipeableTableViewCell: UITableViewCell {
230
235
private func updateSlideDestination( ) {
231
236
if contentOffset. x <= 5 {
232
237
slideDestination = . end
233
- } else if contentOffset. x >= Constants . maxOffset - 5 {
238
+ } else if contentOffset. x >= Constants . maxOffset {
234
239
slideDestination = . begin
235
240
}
236
241
}
@@ -243,8 +248,8 @@ extension SwipeableTableViewCell: UIScrollViewDelegate {
243
248
y: scrollView. contentOffset. y / Constants. contentOffsetMovementDivider
244
249
)
245
250
246
- updateSlideDestination ( )
247
251
updateShape ( )
252
+ updateSlideDestination ( )
248
253
}
249
254
}
250
255
0 commit comments