From 8a88dc077466cff9c5f2daf9185142b311f45270 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 4 Jan 2018 16:00:04 -0500 Subject: Add fix for fast scroll (#124) --- .../ui/widgets/ElasticDragDismissFrameLayout.kt | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'core-ui') 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 = 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 -- cgit v1.2.3