Skip to content

Commit

Permalink
Do not impose scroll limits when configuring alignments manually
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Aug 28, 2024
1 parent c10c28f commit 17c184f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
),
Expand Down Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17c184f

Please sign in to comment.