diff --git a/docs/changelog.md b/docs/changelog.md index 803bab08..00c5ac09 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,12 @@ ## Version 1.3.0 +### 1.3.0-rc01 + +2024-07-08 + +- Reverted default of `setLayoutWhileScrollingEnabled()` back to false. + ### 1.3.0-beta02 2024-06-20 diff --git a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LayoutWhileScrollingTest.kt b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LayoutWhileScrollingTest.kt index 7cd87329..bfa62937 100644 --- a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LayoutWhileScrollingTest.kt +++ b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LayoutWhileScrollingTest.kt @@ -65,6 +65,7 @@ class LayoutWhileScrollingTest : DpadRecyclerViewTest() { // given var layoutCompleted = 0 onRecyclerView("Disable layout during scroll") { recyclerView -> + recyclerView.setLayoutWhileScrollingEnabled(false) recyclerView.addOnLayoutCompletedListener( object : DpadRecyclerView.OnLayoutCompletedListener { override fun onLayoutCompleted(state: RecyclerView.State) { diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt index 43b88b91..5da1f627 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt @@ -72,7 +72,7 @@ open class DpadRecyclerView @JvmOverloads constructor( private var isOverlappingRenderingEnabled = true private var isRetainingFocus = false private var startedTouchScroll = false - private var layoutWhileScrollingEnabled = false + private var layoutWhileScrollingEnabled = true private var hasPendingLayout = false private var touchInterceptListener: OnTouchInterceptListener? = null private var smoothScrollByBehavior: SmoothScrollByBehavior? = null @@ -1298,20 +1298,19 @@ open class DpadRecyclerView @JvmOverloads constructor( fun getOnMotionInterceptListener(): OnMotionInterceptListener? = motionInterceptListener /** - * By default, [DpadRecyclerView] skips layout requests during scrolling because of: + * By default, [DpadRecyclerView] does not skip layout requests during scrolling, + * but you might want to do this because of the following: * 1. Compose animations trigger a full unnecessary layout-pass * 2. Content jumping around while scrolling is not ideal sometimes * * @param enabled true if layout requests should be possible while scrolling, * or false if they should be postponed until [RecyclerView.SCROLL_STATE_IDLE]. - * Default is false. + * Default is true. */ fun setLayoutWhileScrollingEnabled(enabled: Boolean) { layoutWhileScrollingEnabled = enabled } - internal fun isScrollingFromTouch() = startedTouchScroll - @VisibleForTesting internal fun detachFromWindow() { onDetachedFromWindow() diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/PivotLayout.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/PivotLayout.kt index a8b9ee1c..d07de77a 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/PivotLayout.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/layout/PivotLayout.kt @@ -231,17 +231,40 @@ 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?) { diff --git a/gradle.properties b/gradle.properties index 52babd32..6bb35050 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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-beta02 \ No newline at end of file +LIBRARY_VERSION=1.3.0-rc01 \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 7f027445..de5ee0a2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,7 +24,7 @@ theme: extra: dpadrecyclerview: - version: '1.3.0-beta02' + version: '1.3.0-rc01' social: - icon: 'fontawesome/brands/github' link: 'https://github.com/rubensousa/DpadRecyclerView'