From 95bd1d1c3ae995e2f73e7dd308bcc9646ecaad95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Sousa?= Date: Sun, 10 Sep 2023 01:03:56 +0200 Subject: [PATCH] Fix max edge alignment for reverse layout --- .../layoutmanager/alignment/ParentAlignmentCalculator.kt | 3 +++ .../layoutmanager/layout/StructureEngineer.kt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/ParentAlignmentCalculator.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/ParentAlignmentCalculator.kt index 1c72456f..278454b9 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/ParentAlignmentCalculator.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/ParentAlignmentCalculator.kt @@ -225,6 +225,9 @@ internal class ParentAlignmentCalculator { } private fun isLayoutIncomplete(): Boolean { + if (isEndUnknown || isStartUnknown) { + return false + } return if (!reverseLayout) { endEdge < size - paddingEnd } else { diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/StructureEngineer.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/StructureEngineer.kt index 9c7895a6..4e2b4669 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/StructureEngineer.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/StructureEngineer.kt @@ -639,7 +639,7 @@ internal abstract class StructureEngineer( if (startEdge >= layoutInfo.getStartAfterPadding() && preferKeylineOverEdge) { return false } - fixEndGap(startEdge, endEdge, endView, remainingScroll, recycler, state) + fixEndGap(startEdge, endEdge, startView, remainingScroll, recycler, state) return true } else if (layoutRequest.reverseLayout && startEdge >= layoutInfo.getStartAfterPadding()) { if (endEdge <= layoutInfo.getEndAfterPadding() && preferKeylineOverEdge) { @@ -680,7 +680,7 @@ internal abstract class StructureEngineer( state: RecyclerView.State ) { val distanceToStart = max(0, startEdge - layoutInfo.getStartAfterPadding()) - layoutRequest.prepend(layoutInfo.getLayoutPositionOf(endView)) { + layoutRequest.append(layoutInfo.getLayoutPositionOf(endView)) { setCheckpoint(endEdge) setFillSpace(distanceToStart) }