Avoid unnecessary child layout in webtoon recycler
This commit is contained in:
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
import androidx.core.view.ViewCompat.TYPE_TOUCH
|
import androidx.core.view.ViewCompat.TYPE_TOUCH
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@@ -13,12 +14,16 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
private var onPageScrollListeners: MutableList<OnPageScrollListener>? = null
|
private var onPageScrollListeners: MutableList<OnPageScrollListener>? = null
|
||||||
|
private val detachedViews = ArrayList<View>()
|
||||||
|
|
||||||
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
override fun onChildDetachedFromWindow(child: View) {
|
||||||
super.onMeasure(widthSpec, heightSpec)
|
super.onChildDetachedFromWindow(child)
|
||||||
forEach { child ->
|
detachedViews.add(child)
|
||||||
(child as WebtoonFrameLayout).target.requestLayout()
|
}
|
||||||
}
|
|
||||||
|
override fun onChildAttachedToWindow(child: View) {
|
||||||
|
super.onChildAttachedToWindow(child)
|
||||||
|
detachedViews.remove(child)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startNestedScroll(axes: Int) = startNestedScroll(axes, TYPE_TOUCH)
|
override fun startNestedScroll(axes: Int) = startNestedScroll(axes, TYPE_TOUCH)
|
||||||
@@ -106,6 +111,15 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
listeners.forEach { it.dispatchScroll(this, dy, centerPosition) }
|
listeners.forEach { it.dispatchScroll(this, dy, centerPosition) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun relayoutChildren() {
|
||||||
|
forEach { child ->
|
||||||
|
(child as WebtoonFrameLayout).target.requestLayout()
|
||||||
|
}
|
||||||
|
detachedViews.forEach {child ->
|
||||||
|
(child as WebtoonFrameLayout).target.requestLayout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract class OnPageScrollListener {
|
abstract class OnPageScrollListener {
|
||||||
|
|
||||||
private var lastPosition = NO_POSITION
|
private var lastPosition = NO_POSITION
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
defStyles: Int = 0,
|
defStyles: Int = 0,
|
||||||
) : FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener {
|
) : FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener {
|
||||||
|
|
||||||
private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) }
|
private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) as WebtoonRecyclerView }
|
||||||
|
|
||||||
private val scaleDetector = ScaleGestureDetector(context, this)
|
private val scaleDetector = ScaleGestureDetector(context, this)
|
||||||
private val gestureDetector = GestureDetectorCompat(context, GestureListener())
|
private val gestureDetector = GestureDetectorCompat(context, GestureListener())
|
||||||
@@ -96,6 +96,7 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
|||||||
if (newHeight != targetChild.height) {
|
if (newHeight != targetChild.height) {
|
||||||
targetChild.layoutParams.height = newHeight
|
targetChild.layoutParams.height = newHeight
|
||||||
targetChild.requestLayout()
|
targetChild.requestLayout()
|
||||||
|
targetChild.relayoutChildren()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scale < 1) {
|
if (scale < 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user