From 6813459407eb49c5d9718ddf022e361c4170aa0e Mon Sep 17 00:00:00 2001 From: Aashrava Holla Date: Wed, 1 Jul 2020 20:33:44 +0530 Subject: [PATCH] Add a dragResistance property to SwipeActionView (#26) Replaces constant 3 with a property dragResistance when calculating the resistance to drag in a drag event. A validation is added in the setter to make sure the propety is set to 1 or greater. Fix #25 --- .../thanel/swipeactionview/SwipeActionView.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt b/library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt index 570db50..3be140f 100644 --- a/library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt +++ b/library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt @@ -238,6 +238,21 @@ class SwipeActionView : FrameLayout { field = newRatio } + /** + * A factor by which the container view resists a swipe away from the closed position. + * Set this to 1 to get no resistance when swiping. + * Note: Swipe from open to close is always done with no resistance + * + * (Defaults to 3) + */ + var dragResistance = 3 + set(newResistance) { + if (newResistance < 1) { + throw IllegalArgumentException("Drag resistance must be a value greater than or equal to 1. Provided: $newResistance") + } + field = newResistance + } + /** * Listener for the swipe left and right gestures. */ @@ -746,7 +761,7 @@ class SwipeActionView : FrameLayout { // If we are swiping view away from view's default position make the swiping feel much // harder to drag. if (delta > 0 == container.translationX > 0 || container.translationX == 0f) { - delta /= 3 + delta /= dragResistance } container.translationX += delta