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