aboutsummaryrefslogtreecommitdiff
path: root/core-ui/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-01-04 16:00:04 -0500
committerGitHub <noreply@github.com>2018-01-04 16:00:04 -0500
commit8a88dc077466cff9c5f2daf9185142b311f45270 (patch)
treefd8af27f88f130706df45c147d9c5fcfccdc0627 /core-ui/src/main/kotlin
parent2a9d5916a2acd0b468b9aa28977021fdd483e2aa (diff)
downloadkau-8a88dc077466cff9c5f2daf9185142b311f45270.tar.gz
kau-8a88dc077466cff9c5f2daf9185142b311f45270.tar.bz2
kau-8a88dc077466cff9c5f2daf9185142b311f45270.zip
Add fix for fast scroll (#124)
Diffstat (limited to 'core-ui/src/main/kotlin')
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt28
1 files changed, 21 insertions, 7 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
index 6369704..0c9f306 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
@@ -23,6 +23,7 @@ import android.os.Build
import android.support.annotation.RequiresApi
import android.transition.TransitionInflater
import android.util.AttributeSet
+import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import ca.allanwang.kau.logging.KL
@@ -54,6 +55,7 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
private var totalDrag: Float = 0f
private var draggingDown = false
private var draggingUp = false
+ private var lastEvent = -1
private var callbacks: MutableList<ElasticDragDismissCallback> = mutableListOf()
@@ -95,6 +97,11 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
}
+ override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
+ lastEvent = ev.action
+ return super.onInterceptTouchEvent(ev)
+ }
+
override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean {
return nestedScrollAxes and View.SCROLL_AXIS_VERTICAL != 0
}
@@ -116,13 +123,20 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
if (Math.abs(totalDrag) >= dragDismissDistance) {
dispatchDismissCallback()
} else { // settle back to natural position
- animate()
- .translationY(0f)
- .scaleXY(1f)
- .setDuration(200L)
- .setInterpolator(AnimHolder.fastOutSlowInInterpolator(context))
- .setListener(null)
- .start()
+
+ if (lastEvent == MotionEvent.ACTION_DOWN) {
+ translationY = 0f
+ scaleXY = 1f
+ } else {
+ animate()
+ .translationY(0f)
+ .scaleXY(1f)
+ .setDuration(200L)
+ .setInterpolator(AnimHolder.fastOutSlowInInterpolator(context))
+ .setListener(null)
+ .start()
+ }
+
totalDrag = 0f
draggingUp = false
draggingDown = draggingUp