Skip to content

Commit 6813459

Browse files
authored
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
1 parent 03c14d6 commit 6813459

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

library/src/main/kotlin/me/thanel/swipeactionview/SwipeActionView.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ class SwipeActionView : FrameLayout {
238238
field = newRatio
239239
}
240240

241+
/**
242+
* A factor by which the container view resists a swipe away from the closed position.
243+
* Set this to 1 to get no resistance when swiping.
244+
* Note: Swipe from open to close is always done with no resistance
245+
*
246+
* (Defaults to 3)
247+
*/
248+
var dragResistance = 3
249+
set(newResistance) {
250+
if (newResistance < 1) {
251+
throw IllegalArgumentException("Drag resistance must be a value greater than or equal to 1. Provided: $newResistance")
252+
}
253+
field = newResistance
254+
}
255+
241256
/**
242257
* Listener for the swipe left and right gestures.
243258
*/
@@ -746,7 +761,7 @@ class SwipeActionView : FrameLayout {
746761
// If we are swiping view away from view's default position make the swiping feel much
747762
// harder to drag.
748763
if (delta > 0 == container.translationX > 0 || container.translationX == 0f) {
749-
delta /= 3
764+
delta /= dragResistance
750765
}
751766

752767
container.translationX += delta

0 commit comments

Comments
 (0)