mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
Stop tap zones from triggering when scrolling is stopped by tapping (#2680)
This commit is contained in:
@@ -103,6 +103,7 @@ class WebtoonFrame(context: Context) : FrameLayout(context) {
|
||||
velocityX: Float,
|
||||
velocityY: Float,
|
||||
): Boolean {
|
||||
recycler?.onManualScroll()
|
||||
return recycler?.zoomFling(velocityX.toInt(), velocityY.toInt()) ?: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,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
|
||||
@@ -63,6 +66,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)
|
||||
}
|
||||
@@ -82,6 +89,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 {
|
||||
@@ -212,10 +223,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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user