From 0705ce08f64bd42245d57ec84f3a1df98e728aa9 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Tue, 4 Jun 2024 03:15:46 +0200 Subject: [PATCH] Find first focusable view starting from adapter order --- .../layoutmanager/layout/PivotLayout.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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 50a9eb3e..a8b9ee1c 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 @@ -215,16 +215,10 @@ internal class PivotLayout( } private fun findFirstFocusableView(): View? { - val childCount = layoutInfo.getChildCount() - for (i in 0 until childCount) { - val actualIndex = if (layoutInfo.shouldReverseLayout()) { - childCount - 1 - i - } else { - i - } - val child = layoutInfo.getChildAt(actualIndex) - if (child != null && child.hasFocusable()) { - return child + for (i in 0 until layoutManager.itemCount) { + val view = layoutInfo.findViewByAdapterPosition(i) + if (view != null && layoutInfo.isViewFocusable(view)) { + return view } } return null