@@ -94,12 +94,6 @@ class SwipeActionView : FrameLayout {
9494 */
9595 private val handler = PressTimeoutHandler (this )
9696
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-
10397 /* *
10498 * Ripple displayed after performing swipe left gesture.
10599 */
@@ -198,12 +192,14 @@ class SwipeActionView : FrameLayout {
198192 /* *
199193 * The minimum distance required to execute swipe callbacks when swiping to the left side.
200194 */
201- private var minLeftActivationDistance = 0f
195+ private val minLeftActivationDistance: Float
196+ get() = activationDistanceRatio * maxLeftSwipeDistance
202197
203198 /* *
204199 * The minimum distance required to execute swipe callbacks when swiping to the right side.
205200 */
206- private var minRightActivationDistance = 0f
201+ private val minRightActivationDistance: Float
202+ get() = activationDistanceRatio * maxRightSwipeDistance
207203
208204 /* *
209205 * Determines whether ripple drawables should have padding.
@@ -230,6 +226,18 @@ class SwipeActionView : FrameLayout {
230226 */
231227 private var onLongClickListener: OnLongClickListener ? = null
232228
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+
233241 /* *
234242 * Listener for the swipe left and right gestures.
235243 */
@@ -347,15 +355,13 @@ class SwipeActionView : FrameLayout {
347355 leftSwipeRipple.maxRadius = maxRadius
348356 rightSwipeRipple.maxRadius = maxRadius
349357
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
354361
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
359365
360366 if (isInEditMode) {
361367 when (previewBackground) {
@@ -541,7 +547,9 @@ class SwipeActionView : FrameLayout {
541547 }
542548
543549 MotionEvent .ACTION_UP -> {
544- if (isClickable && isTouchValid && ! dragging && ! inLongPress && ! hasMovedVertically(e)) {
550+ if (isClickable && isTouchValid && ! dragging && ! inLongPress
551+ && ! hasMovedVertically(e)
552+ ) {
545553 startPress(e.x, e.y)
546554 performClick()
547555 }
0 commit comments