Skip to content

Commit

Permalink
Expose setContent
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Jun 2, 2024
1 parent 963f610 commit 588908c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 10 additions & 2 deletions dpadrecyclerview-compose/api/dpadrecyclerview-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()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;
}
Expand All @@ -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 <init> (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function5;)V
public synthetic fun <init> (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 <init> (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;Lkotlin/jvm/functions/Function4;)V
public synthetic fun <init> (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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ class DpadComposeViewHolder<T>(
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<T?>(null)
private val composeView = itemView as DpadComposeView

init {
val composeView = itemView as DpadComposeView
composeView.apply {
setFocusConfiguration(
isFocusable = isFocusable,
Expand All @@ -81,7 +79,7 @@ class DpadComposeViewHolder<T>(
setViewCompositionStrategy(compositionStrategy)
setContent {
itemState.value?.let { item ->
content(item, focusState.value, this@DpadComposeViewHolder)
content(item, focusState.value)
}
}
}
Expand All @@ -98,6 +96,14 @@ class DpadComposeViewHolder<T>(
}
}

fun setContent(content: @Composable (item: T) -> Unit) {
composeView.setContent {
itemState.value?.let { item ->
content(item)
}
}
}

fun setItemState(item: T?) {
itemState.value = item
}
Expand Down

0 comments on commit 588908c

Please sign in to comment.