Optimize webtoon scroll
This commit is contained in:
@@ -2,16 +2,27 @@ package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlin.math.sign
|
||||
|
||||
class WebtoonRecyclerView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||
|
||||
override fun startNestedScroll(axes: Int) = startNestedScroll(axes, ViewCompat.TYPE_TOUCH)
|
||||
|
||||
override fun startNestedScroll(axes: Int, type: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun dispatchNestedPreScroll(
|
||||
dx: Int,
|
||||
dy: Int,
|
||||
consumed: IntArray?,
|
||||
offsetInWindow: IntArray?
|
||||
) = dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, ViewCompat.TYPE_TOUCH)
|
||||
|
||||
override fun dispatchNestedPreScroll(
|
||||
dx: Int,
|
||||
dy: Int,
|
||||
@@ -20,21 +31,11 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
||||
type: Int
|
||||
): Boolean {
|
||||
val consumedY = consumeVerticalScroll(dy)
|
||||
val superRes = super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type)
|
||||
consumed?.set(1, consumed[1] + consumedY)
|
||||
return superRes || consumedY != 0
|
||||
}
|
||||
|
||||
override fun dispatchNestedPreScroll(
|
||||
dx: Int,
|
||||
dy: Int,
|
||||
consumed: IntArray?,
|
||||
offsetInWindow: IntArray?
|
||||
): Boolean {
|
||||
val consumedY = consumeVerticalScroll(dy)
|
||||
val superRes = super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
|
||||
consumed?.set(1, consumed[1] + consumedY)
|
||||
return superRes || consumedY != 0
|
||||
if (consumed != null) {
|
||||
consumed[0] = 0
|
||||
consumed[1] = consumedY
|
||||
}
|
||||
return consumedY != 0
|
||||
}
|
||||
|
||||
private fun consumeVerticalScroll(dy: Int): Int {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.ui.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import kotlin.system.exitProcess
|
||||
@@ -22,7 +23,7 @@ class AppCrashHandler(private val applicationContext: Context) : Thread.Uncaught
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
e.printStackTrace()
|
||||
Log.e("CRASH", e.message, e)
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user