@@ -94,12 +94,6 @@ class SwipeActionView : FrameLayout {
94
94
*/
95
95
private val handler = PressTimeoutHandler (this )
96
96
97
- /* *
98
- * The percentage of the [maxLeftSwipeDistance] or [maxRightSwipeDistance] after which swipe
99
- * callbacks can can be executed.
100
- */
101
- private val minActivationDistanceRatio = 0.8f
102
-
103
97
/* *
104
98
* Ripple displayed after performing swipe left gesture.
105
99
*/
@@ -198,12 +192,14 @@ class SwipeActionView : FrameLayout {
198
192
/* *
199
193
* The minimum distance required to execute swipe callbacks when swiping to the left side.
200
194
*/
201
- private var minLeftActivationDistance = 0f
195
+ private val minLeftActivationDistance: Float
196
+ get() = activationDistanceRatio * maxLeftSwipeDistance
202
197
203
198
/* *
204
199
* The minimum distance required to execute swipe callbacks when swiping to the right side.
205
200
*/
206
- private var minRightActivationDistance = 0f
201
+ private val minRightActivationDistance: Float
202
+ get() = activationDistanceRatio * maxRightSwipeDistance
207
203
208
204
/* *
209
205
* Determines whether ripple drawables should have padding.
@@ -230,6 +226,18 @@ class SwipeActionView : FrameLayout {
230
226
*/
231
227
private var onLongClickListener: OnLongClickListener ? = null
232
228
229
+ /* *
230
+ * The percentage of the swipe distance (width of the revealed view) after which swipe
231
+ * callbacks should be executed. (Defaults to 80%)
232
+ */
233
+ var activationDistanceRatio = 0.8f
234
+ set(newRatio) {
235
+ if (newRatio < 0f || newRatio > 1f ) {
236
+ throw IllegalArgumentException (" Activation distance ratio must be a value in range <0.0f, 1.0f>. Provided: $newRatio " )
237
+ }
238
+ field = newRatio
239
+ }
240
+
233
241
/* *
234
242
* Listener for the swipe left and right gestures.
235
243
*/
@@ -347,15 +355,13 @@ class SwipeActionView : FrameLayout {
347
355
leftSwipeRipple.maxRadius = maxRadius
348
356
rightSwipeRipple.maxRadius = maxRadius
349
357
350
- leftSwipeView?.let {
351
- maxLeftSwipeDistance = it.totalWidth.toFloat() - container.marginEnd
352
- minLeftActivationDistance = minActivationDistanceRatio * maxLeftSwipeDistance
353
- }
358
+ maxLeftSwipeDistance = leftSwipeView?.let {
359
+ it.totalWidth.toFloat() - container.marginEnd
360
+ } ? : 0f
354
361
355
- rightSwipeView?.let {
356
- maxRightSwipeDistance = it.totalWidth.toFloat() - container.marginStart
357
- minRightActivationDistance = minActivationDistanceRatio * maxRightSwipeDistance
358
- }
362
+ maxRightSwipeDistance = rightSwipeView?.let {
363
+ it.totalWidth.toFloat() - container.marginStart
364
+ } ? : 0f
359
365
360
366
if (isInEditMode) {
361
367
when (previewBackground) {
@@ -541,7 +547,9 @@ class SwipeActionView : FrameLayout {
541
547
}
542
548
543
549
MotionEvent .ACTION_UP -> {
544
- if (isClickable && isTouchValid && ! dragging && ! inLongPress && ! hasMovedVertically(e)) {
550
+ if (isClickable && isTouchValid && ! dragging && ! inLongPress
551
+ && ! hasMovedVertically(e)
552
+ ) {
545
553
startPress(e.x, e.y)
546
554
performClick()
547
555
}
0 commit comments