Fix webtoon last visible item position calculation (#562)

Covers the case when image height > screen height.
This commit is contained in:
FooIbar 2024-03-22 20:56:48 +08:00 committed by GitHub
parent 6682b5dd39
commit 34930920a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,20 +36,21 @@ class WebtoonLayoutManager(context: Context) : LinearLayoutManager(context) {
*/ */
fun findLastEndVisibleItemPosition(): Int { fun findLastEndVisibleItemPosition(): Int {
ensureLayoutState() ensureLayoutState()
@ViewBoundsCheck.ViewBounds val preferredBoundsFlag = val callback = if (mOrientation == HORIZONTAL) {
(ViewBoundsCheck.FLAG_CVE_LT_PVE or ViewBoundsCheck.FLAG_CVE_EQ_PVE)
val fromIndex = childCount - 1
val toIndex = -1
val child = if (mOrientation == HORIZONTAL) {
mHorizontalBoundCheck mHorizontalBoundCheck
.findOneViewWithinBoundFlags(fromIndex, toIndex, preferredBoundsFlag, 0)
} else { } else {
mVerticalBoundCheck mVerticalBoundCheck
.findOneViewWithinBoundFlags(fromIndex, toIndex, preferredBoundsFlag, 0) }.mCallback
val start = callback.parentStart
val end = callback.parentEnd
for (i in childCount - 1 downTo 0) {
val child = getChildAt(i)!!
val childStart = callback.getChildStart(child)
val childEnd = callback.getChildEnd(child)
if (childEnd <= end || childStart < start) {
return getPosition(child)
}
} }
return NO_POSITION
return if (child == null) NO_POSITION else getPosition(child)
} }
} }