From 80680c02ea7ed4669c14f64c987e60686e188033 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Mon, 8 Jul 2024 23:00:01 +0200 Subject: [PATCH 1/5] Revert layoutWhileScrolling back to true --- .../test/tests/layout/LayoutWhileScrollingTest.kt | 1 + .../java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) 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..1bdf60bd 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 @@ -1304,7 +1304,7 @@ open class DpadRecyclerView @JvmOverloads constructor( * * @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 From 37629be5be289a288be9eca38e59037fd4ff1fbf Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Mon, 8 Jul 2024 23:00:47 +0200 Subject: [PATCH 2/5] Bump to 1.3.0-rc01 --- docs/changelog.md | 6 ++++++ gradle.properties | 2 +- mkdocs.yml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) 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/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' From 3372151895b735cda767e56bb7f8fb006912ef10 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Mon, 8 Jul 2024 23:03:04 +0200 Subject: [PATCH 3/5] Update docs --- .../java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt index 1bdf60bd..5a4ceeb9 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt @@ -1298,7 +1298,8 @@ 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 * From a33c8d649c1db1b54d11268ffa593a8100c51d1c Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Mon, 8 Jul 2024 23:03:19 +0200 Subject: [PATCH 4/5] Remove method not used --- .../java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt index 5a4ceeb9..5da1f627 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt @@ -1311,8 +1311,6 @@ open class DpadRecyclerView @JvmOverloads constructor( layoutWhileScrollingEnabled = enabled } - internal fun isScrollingFromTouch() = startedTouchScroll - @VisibleForTesting internal fun detachFromWindow() { onDetachedFromWindow() From 7243741eea239e31cd5e59dea7b74e6b7170c50e Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Tue, 9 Jul 2024 00:01:32 +0200 Subject: [PATCH 5/5] Stop scrolling and trigger layout request when item changes affect the layout structure --- .../layoutmanager/layout/PivotLayout.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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?) {