Skip to content

Commit

Permalink
Add a dragResistance property to SwipeActionView (#26)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
teal77 authored Jul 1, 2020
1 parent 03c14d6 commit 6813459
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6813459

Please sign in to comment.