From 05536f5c1a9a63614bb0a844c65bbebd684f6fb1 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Thu, 26 Sep 2024 02:15:57 +0200 Subject: [PATCH] Cancel scrolling to target before updating the layout --- .../dpadrecyclerview/layoutmanager/PivotLayoutManager.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt index 35c5d1ed..d4dc7d7e 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotLayoutManager.kt @@ -145,13 +145,13 @@ class PivotLayoutManager(properties: Properties) : RecyclerView.LayoutManager(), override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) { // If we have focus, save it temporarily since the views will change and we might lose it hadFocusBeforeLayout = hasFocus() + if (layoutInfo.isScrollingToTarget) { + scroller.cancelScrollToTarget() + } pivotLayout.onLayoutChildren(recycler, state) if (hadFocusBeforeLayout) { focusDispatcher.focusSelectedView() } - if (layoutInfo.isScrollingToTarget) { - scroller.cancelScrollToTarget() - } hadFocusBeforeLayout = false }