Stop tap zones from triggering when scrolling is stopped by tapping (mihonapp/mihon#2680)
(cherry picked from commit 2ec67ac0c1831a68d8d73e2679f8c98a5a48acf5)
This commit is contained in:
parent
f225e611c6
commit
9ade58cc95
2 changed files with 19 additions and 1 deletions
|
|
@ -111,6 +111,7 @@ class WebtoonFrame(context: Context) : FrameLayout(context) {
|
|||
velocityX: Float,
|
||||
velocityY: Float,
|
||||
): Boolean {
|
||||
recycler?.onManualScroll()
|
||||
return recycler?.zoomFling(velocityX.toInt(), velocityY.toInt()) ?: false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||
var tapListener: ((MotionEvent) -> Unit)? = null
|
||||
var longTapListener: ((MotionEvent) -> Boolean)? = null
|
||||
|
||||
private var isManuallyScrolling = false
|
||||
private var tapDuringManualScroll = false
|
||||
|
||||
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
||||
halfWidth = MeasureSpec.getSize(widthSpec) / 2
|
||||
halfHeight = MeasureSpec.getSize(heightSpec) / 2
|
||||
|
|
@ -67,6 +70,10 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override fun onTouchEvent(e: MotionEvent): Boolean {
|
||||
if (e.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
tapDuringManualScroll = isManuallyScrolling
|
||||
}
|
||||
|
||||
detector.onTouchEvent(e)
|
||||
return super.onTouchEvent(e)
|
||||
}
|
||||
|
|
@ -86,6 +93,10 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||
val totalItemCount = layoutManager?.itemCount ?: 0
|
||||
atLastPosition = visibleItemCount > 0 && lastVisibleItemPosition == totalItemCount - 1
|
||||
atFirstPosition = firstVisibleItemPosition == 0
|
||||
|
||||
if (state == SCROLL_STATE_IDLE) {
|
||||
isManuallyScrolling = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPositionX(positionX: Float): Float {
|
||||
|
|
@ -224,10 +235,16 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun onManualScroll() {
|
||||
isManuallyScrolling = true
|
||||
}
|
||||
|
||||
inner class GestureListener : GestureDetectorWithLongTap.Listener() {
|
||||
|
||||
override fun onSingleTapConfirmed(ev: MotionEvent): Boolean {
|
||||
tapListener?.invoke(ev)
|
||||
if (!tapDuringManualScroll) {
|
||||
tapListener?.invoke(ev)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue