diff --git a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/alignment/AlignmentLookupTest.kt b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/alignment/AlignmentLookupTest.kt index ad56d47c..9bf33d7f 100644 --- a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/alignment/AlignmentLookupTest.kt +++ b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/alignment/AlignmentLookupTest.kt @@ -21,7 +21,6 @@ import com.google.common.truth.Truth.assertThat import com.rubensousa.dpadrecyclerview.AlignmentLookup import com.rubensousa.dpadrecyclerview.ChildAlignment import com.rubensousa.dpadrecyclerview.ParentAlignment -import com.rubensousa.dpadrecyclerview.ParentAlignment.Edge import com.rubensousa.dpadrecyclerview.test.TestLayoutConfiguration import com.rubensousa.dpadrecyclerview.test.helpers.getItemViewBounds import com.rubensousa.dpadrecyclerview.test.helpers.getRecyclerViewBounds @@ -44,7 +43,7 @@ class AlignmentLookupTest : DpadRecyclerViewTest() { spans = 1, orientation = RecyclerView.VERTICAL, parentAlignment = ParentAlignment( - edge = Edge.MIN_MAX, + edge = ParentAlignment.Edge.MIN_MAX, offset = 0, fraction = 0f ), @@ -147,4 +146,44 @@ class AlignmentLookupTest : DpadRecyclerViewTest() { } } + @Test + fun testScrollIsStillAppliedAfterFastScrolling() { + // given + launchFragment() + val bottomParentAlignment = ParentAlignment(fraction = 1f) + val bottomChildAlignment = ChildAlignment(fraction = 1f) + val recyclerViewBounds = getRecyclerViewBounds() + + onRecyclerView("Set alignment") { recyclerView -> + recyclerView.setAlignmentLookup(object : AlignmentLookup { + override fun getParentAlignment( + viewHolder: RecyclerView.ViewHolder, + ): ParentAlignment? { + if (viewHolder.layoutPosition == 0) { + return bottomParentAlignment + } + return null + } + + override fun getChildAlignment(viewHolder: RecyclerView.ViewHolder): ChildAlignment? { + if (viewHolder.layoutPosition == 0) { + return bottomChildAlignment + } + return null + } + }) + } + waitForLayout() + + // when + KeyEvents.pressDown(times = 10) + waitForIdleScrollState() + KeyEvents.pressUp(times = 10) + waitForIdleScrollState() + + // then + val viewBounds = getItemViewBounds(position = 0) + assertThat(viewBounds.bottom).isEqualTo(recyclerViewBounds.bottom) + } + } diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/LayoutAlignment.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/LayoutAlignment.kt index 0e24e3f4..574ead05 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/LayoutAlignment.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/alignment/LayoutAlignment.kt @@ -216,6 +216,14 @@ internal class LayoutAlignment( if (itemCount == 0) { return } + /** + * Client wants to specify the alignments manually, + * so we shouldn't impose any scroll limits + */ + if (alignmentLookup != null) { + parentAlignmentCalculator.invalidateScrollLimits() + return + } val endAdapterPos: Int val startAdapterPos: Int val endLayoutPos: Int