Skip to content

Commit

Permalink
Merge pull request #238 from rubensousa/scrolling_bug
Browse files Browse the repository at this point in the history
Fix smooth scroller not stopping the scroll action in some scenarios
  • Loading branch information
rubensousa authored Jul 11, 2024
2 parents b630502 + f015e9c commit 1f46d03
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Version 1.3.0

### 1.3.0-rc02

2024-07-11

#### Bug fixes

- Fixed `DpadRecyclerView` not immediately stopping the search for the pivot in some scenarios ([#238](https://github.com/rubensousa/DpadRecyclerView/pull/238))

### 1.3.0-rc01

2024-07-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class VerticalGridScrollTest : DpadRecyclerViewTest() {
fun testMultipleFastDifferentSpanFocusChanges() {
launchFragment()
onRecyclerView("Change span size lookup") { recyclerView ->
recyclerView.setSmoothScrollMaxPendingMoves(25)
recyclerView.setSpanSizeLookup(object : DpadSpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (position == 0 || position.rem(spanCount + 1) == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,40 +231,17 @@ internal class PivotLayout(
fun onItemsAdded(positionStart: Int, itemCount: Int) {
itemChanges.insertionPosition = positionStart
itemChanges.insertionItemCount = itemCount
onItemsChanged()
}

fun onItemsRemoved(positionStart: Int, itemCount: Int) {
itemChanges.removalPosition = positionStart
itemChanges.removalItemCount = itemCount
onItemsChanged()
}

fun onItemsMoved(from: Int, to: Int, itemCount: Int) {
itemChanges.moveFromPosition = from
itemChanges.moveToPosition = to
itemChanges.moveItemCount = itemCount
onItemsChanged()
}

private fun onItemsChanged() {
if (!layoutInfo.isScrolling) {
return
}
val firstPos = layoutInfo.findFirstAddedPosition()
val lastPos = layoutInfo.findLastAddedPosition()
val changesOutOfBounds = if (!layoutInfo.shouldReverseLayout()) {
itemChanges.isOutOfBounds(firstPos, lastPos)
} else {
itemChanges.isOutOfBounds(lastPos, firstPos)
}
if (changesOutOfBounds) {
return
}
layoutInfo.getRecyclerView()?.apply {
stopScroll()
requestLayout()
}
}

fun setOnChildLaidOutListener(listener: OnChildLaidOutListener?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ internal open class BaseSmoothScroller(

fun cancel() {
isCanceled = true
layoutInfo.getRecyclerView()?.apply {
postOnAnimation {
if (layoutInfo.isScrolling) {
requestLayout()
}
stopScroll()
}
}
}

fun isCanceled(): Boolean = isCanceled
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.enableR8.fullMode=true
LIBRARY_VERSION=1.3.0-rc01
LIBRARY_VERSION=1.3.0-rc02
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ theme:

extra:
dpadrecyclerview:
version: '1.3.0-rc01'
version: '1.3.0-rc02'
social:
- icon: 'fontawesome/brands/github'
link: 'https://github.com/rubensousa/DpadRecyclerView'
Expand Down

0 comments on commit 1f46d03

Please sign in to comment.