diff --git a/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api b/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api index 6adf4be7..7398182a 100644 --- a/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api +++ b/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api @@ -4,9 +4,10 @@ public final class com/rubensousa/dpadrecyclerview/compose/DpadComposeExtensions public final class com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewHolder : androidx/recyclerview/widget/RecyclerView$ViewHolder { public static final field $stable I - public fun (Landroid/view/ViewGroup;Landroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function3;)V - public synthetic fun (Landroid/view/ViewGroup;Landroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Landroid/view/ViewGroup;Landroidx/compose/ui/platform/ViewCompositionStrategy;ZLkotlin/jvm/functions/Function3;)V + public synthetic fun (Landroid/view/ViewGroup;Landroidx/compose/ui/platform/ViewCompositionStrategy;ZLkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getItem ()Ljava/lang/Object; + public final fun setFocusable (Z)V public final fun setItemState (Ljava/lang/Object;)V } diff --git a/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewHolder.kt b/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewHolder.kt index 5ca546f6..3cc63ad3 100644 --- a/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewHolder.kt +++ b/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewHolder.kt @@ -19,7 +19,6 @@ package com.rubensousa.dpadrecyclerview.compose import android.view.ViewGroup import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.recyclerview.widget.RecyclerView @@ -46,17 +45,16 @@ import androidx.recyclerview.widget.RecyclerView class DpadComposeFocusViewHolder( parent: ViewGroup, compositionStrategy: ViewCompositionStrategy = RecyclerViewCompositionStrategy.DisposeOnRecycled, + isFocusable: Boolean = true, private val content: @Composable (item: T) -> Unit -) : RecyclerView.ViewHolder(ComposeView(parent.context)) { +) : RecyclerView.ViewHolder(DpadComposeView(parent.context)) { private val itemState = mutableStateOf(null) - private val composeView = itemView as ComposeView + private val composeView = itemView as DpadComposeView init { composeView.apply { - isFocusable = true - isFocusableInTouchMode = true - descendantFocusability = ViewGroup.FOCUS_AFTER_DESCENDANTS + this@DpadComposeFocusViewHolder.setFocusable(isFocusable) setViewCompositionStrategy(compositionStrategy) setContent { itemState.value?.let { item -> diff --git a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/grid/GridSpanHeaderFragment.kt b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/grid/GridSpanHeaderFragment.kt index 3669bc03..d47c96c5 100644 --- a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/grid/GridSpanHeaderFragment.kt +++ b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/grid/GridSpanHeaderFragment.kt @@ -103,7 +103,10 @@ class GridSpanHeaderFragment : Fragment(R.layout.screen_recyclerview) { } else -> { - DpadComposeFocusViewHolder(parent) { _ -> + DpadComposeFocusViewHolder( + parent, + isFocusable = false + ) { _ -> Text( modifier = Modifier.padding( horizontal = 48.dp, @@ -113,8 +116,6 @@ class GridSpanHeaderFragment : Fragment(R.layout.screen_recyclerview) { color = Color.White, style = MaterialTheme.typography.titleLarge, ) - }.also { - it.setFocusable(false) } } }