diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonRecyclerView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonRecyclerView.kt index ba3a4653e..4ec3edaa6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonRecyclerView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonRecyclerView.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon import android.content.Context import android.util.AttributeSet +import android.view.View import androidx.core.view.ViewCompat.TYPE_TOUCH import androidx.core.view.forEach import androidx.recyclerview.widget.RecyclerView @@ -13,12 +14,16 @@ class WebtoonRecyclerView @JvmOverloads constructor( ) : RecyclerView(context, attrs, defStyleAttr) { private var onPageScrollListeners: MutableList? = null + private val detachedViews = ArrayList() - override fun onMeasure(widthSpec: Int, heightSpec: Int) { - super.onMeasure(widthSpec, heightSpec) - forEach { child -> - (child as WebtoonFrameLayout).target.requestLayout() - } + override fun onChildDetachedFromWindow(child: View) { + super.onChildDetachedFromWindow(child) + detachedViews.add(child) + } + + override fun onChildAttachedToWindow(child: View) { + super.onChildAttachedToWindow(child) + detachedViews.remove(child) } override fun startNestedScroll(axes: Int) = startNestedScroll(axes, TYPE_TOUCH) @@ -106,6 +111,15 @@ class WebtoonRecyclerView @JvmOverloads constructor( 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 { private var lastPosition = NO_POSITION diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt index eb49fe71f..d871b3320 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt @@ -23,7 +23,7 @@ class WebtoonScalingFrame @JvmOverloads constructor( defStyles: Int = 0, ) : 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 gestureDetector = GestureDetectorCompat(context, GestureListener()) @@ -96,6 +96,7 @@ class WebtoonScalingFrame @JvmOverloads constructor( if (newHeight != targetChild.height) { targetChild.layoutParams.height = newHeight targetChild.requestLayout() + targetChild.relayoutChildren() } if (scale < 1) {