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 ++++++++++++++++------ docs/Changelog.md | 5 ++++ sample/src/main/res/xml/kau_changelog.xml | 7 ++++++ 3 files changed, 33 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 = 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 diff --git a/docs/Changelog.md b/docs/Changelog.md index 88fe4ff..88931e7 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,10 @@ # Changelog +## v3.6.2 +* :core: Create more bundle utils to help with shared transition elements +* :searchview: Add better encapsulation and use view location +* :searchview: Add textClearedCallback + ## v3.6.1 * :core: [Breaking] Removed private text field and introduced lazy logging functions * :adapter: Improve library item layout diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index a4c4f95..09e5896 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -7,6 +7,13 @@ --> + + + + + + + -- cgit v1.2.3