Skip to content

Commit 242f292

Browse files
authored
Made changes to support listening to the end of the swipe action (#30)
1 parent 6813459 commit 242f292

File tree

16 files changed

+136
-67
lines changed

16 files changed

+136
-67
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
/build
1010
/captures
1111
.idea/caches
12+
/.idea
13+
*~
14+
*.apk
15+
*.swp
16+
captures
17+

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.idea/copyright/Apache_2_0.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/copyright/profiles_settings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/gradle.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/runConfigurations.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/wrapper/gradle-wrapper.jar

5.15 KB
Binary file not shown.

library/build.gradle

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'com.github.dcendents.android-maven'
3+
apply plugin: 'maven-publish'
44

5-
group = 'com.github.Tunous'
65

76
android {
87
compileSdkVersion 28
@@ -18,6 +17,21 @@ android {
1817
}
1918
}
2019

20+
publishing {
21+
publications {
22+
release(MavenPublication) {
23+
artifact(bundleReleaseAar)
24+
artifact sourcesJar
25+
artifact javadocJar
26+
27+
groupId = 'com.github.Tunous'
28+
artifactId = 'SwipeActionView'
29+
version = '1.4.0-SNAPSHOT'
30+
}
31+
}
32+
}
33+
34+
2135
dependencies {
2236
implementation 'androidx.appcompat:appcompat:1.0.2'
2337
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@@ -40,7 +54,4 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
4054
from javadoc.destinationDir
4155
}
4256

43-
artifacts {
44-
archives sourcesJar
45-
archives javadocJar
46-
}
57+

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ import android.os.Build
2828
import android.os.Handler
2929
import android.os.Message
3030
import android.util.AttributeSet
31-
import android.view.MotionEvent
32-
import android.view.VelocityTracker
33-
import android.view.View
34-
import android.view.ViewConfiguration
31+
import android.view.*
3532
import android.view.animation.DecelerateInterpolator
3633
import android.widget.FrameLayout
3734
import androidx.annotation.ColorInt
@@ -253,6 +250,15 @@ class SwipeActionView : FrameLayout {
253250
field = newResistance
254251
}
255252

253+
254+
/**
255+
* The delay for the view to start the reset animation after swiping left or right.
256+
* The value is in milliseconds.
257+
*
258+
* (Defaults to 200 ms)
259+
*/
260+
var resetDelay = 200L
261+
256262
/**
257263
* Listener for the swipe left and right gestures.
258264
*/
@@ -471,16 +477,20 @@ class SwipeActionView : FrameLayout {
471477
animateToOriginalPosition(startDelay)
472478
}
473479

480+
474481
/**
475482
* Animate the view to its original position.
476483
*
477484
* @param startDelay The amount of delay, in milliseconds, to wait before starting the
478485
* movement animation. (Defaults to 0)
486+
*
487+
* @param completeCallback Will be run at the end of the animation. (By default does nothing)
479488
*/
480489
@JvmOverloads
481-
fun animateToOriginalPosition(startDelay: Long = 0) {
490+
fun animateToOriginalPosition(startDelay: Long = 0, completeCallback: () -> Unit = {}) {
482491
animateContainer(0f, swipeAnimationDuration, startDelay) {
483492
canPerformSwipeAction = true
493+
completeCallback()
484494
}
485495
}
486496

@@ -852,7 +862,13 @@ class SwipeActionView : FrameLayout {
852862
}
853863

854864
if (shouldFinish != false) {
855-
animateToOriginalPosition(200)
865+
animateToOriginalPosition(resetDelay) {
866+
if (swipedRight) {
867+
swipeGestureListener?.onSwipeRightComplete(this)
868+
} else {
869+
swipeGestureListener?.onSwipeLeftComplete(this)
870+
}
871+
}
856872
}
857873
}
858874
}

0 commit comments

Comments
 (0)