From 588908c47ff1b7fbbba114fd386f81561afae977 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Sun, 2 Jun 2024 11:13:21 +0200 Subject: [PATCH] Expose setContent --- .../api/dpadrecyclerview-compose.api | 12 ++++++++++-- .../compose/DpadComposeViewHolder.kt | 16 +++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api b/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api index 7baf5b0c..3409f89c 100644 --- a/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api +++ b/dpadrecyclerview-compose/api/dpadrecyclerview-compose.api @@ -5,6 +5,13 @@ public final class com/rubensousa/dpadrecyclerview/compose/ComposableSingletons$ public final fun getLambda-1$dpadrecyclerview_compose_release ()Lkotlin/jvm/functions/Function3; } +public final class com/rubensousa/dpadrecyclerview/compose/ComposableSingletons$DpadComposeViewHolderKt { + public static final field INSTANCE Lcom/rubensousa/dpadrecyclerview/compose/ComposableSingletons$DpadComposeViewHolderKt; + public static field lambda-1 Lkotlin/jvm/functions/Function4; + public fun ()V + public final fun getLambda-1$dpadrecyclerview_compose_release ()Lkotlin/jvm/functions/Function4; +} + public final class com/rubensousa/dpadrecyclerview/compose/DpadComposeExtensionsKt { public static final fun dpadClickable (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/Modifier; } @@ -20,9 +27,10 @@ public final class com/rubensousa/dpadrecyclerview/compose/DpadComposeFocusViewH public final class com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder : androidx/recyclerview/widget/RecyclerView$ViewHolder { public static final field $stable I - public fun (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function5;)V - public synthetic fun (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function5;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function4;)V + public synthetic fun (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getItem ()Ljava/lang/Object; + public final fun setContent (Lkotlin/jvm/functions/Function3;)V public final fun setItemState (Ljava/lang/Object;)V } diff --git a/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder.kt b/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder.kt index 673cdf96..464bfa11 100644 --- a/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder.kt +++ b/dpadrecyclerview-compose/src/main/java/com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder.kt @@ -60,16 +60,14 @@ class DpadComposeViewHolder( onLongClick: ((item: T) -> Boolean)? = null, isFocusable: Boolean = true, compositionStrategy: ViewCompositionStrategy = RecyclerViewCompositionStrategy.DisposeOnRecycled, - private val content: @Composable ( - item: T, isFocused: Boolean, viewHolder: RecyclerView.ViewHolder - ) -> Unit + private val content: @Composable (item: T, isFocused: Boolean) -> Unit = { _, _ -> } ) : RecyclerView.ViewHolder(DpadComposeView(parent.context)) { private val focusState = mutableStateOf(false) private val itemState = mutableStateOf(null) + private val composeView = itemView as DpadComposeView init { - val composeView = itemView as DpadComposeView composeView.apply { setFocusConfiguration( isFocusable = isFocusable, @@ -81,7 +79,7 @@ class DpadComposeViewHolder( setViewCompositionStrategy(compositionStrategy) setContent { itemState.value?.let { item -> - content(item, focusState.value, this@DpadComposeViewHolder) + content(item, focusState.value) } } } @@ -98,6 +96,14 @@ class DpadComposeViewHolder( } } + fun setContent(content: @Composable (item: T) -> Unit) { + composeView.setContent { + itemState.value?.let { item -> + content(item) + } + } + } + fun setItemState(item: T?) { itemState.value = item }