Skip to content

Commit

Permalink
Add extra optional constructor argument for switching the composition…
Browse files Browse the repository at this point in the history
… strategy
  • Loading branch information
rubensousa committed Jan 28, 2024
1 parent e72faa5 commit 51be18e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions dpadrecyclerview-compose/api/dpadrecyclerview-compose.api
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public abstract class com/rubensousa/dpadrecyclerview/compose/DpadAbstractComposeViewHolder : androidx/recyclerview/widget/RecyclerView$ViewHolder, com/rubensousa/dpadrecyclerview/DpadViewHolder {
public static final field $stable I
public fun <init> (Landroid/view/ViewGroup;Z)V
public synthetic fun <init> (Landroid/view/ViewGroup;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Landroid/view/ViewGroup;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;)V
public synthetic fun <init> (Landroid/view/ViewGroup;ZLandroidx/compose/ui/platform/ViewCompositionStrategy;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public abstract fun Content (Ljava/lang/Object;ZZLandroidx/compose/runtime/Composer;I)V
public final fun getItem ()Ljava/lang/Object;
public fun getSubPositionAlignments ()Ljava/util/List;
Expand All @@ -14,8 +14,8 @@ public abstract class com/rubensousa/dpadrecyclerview/compose/DpadAbstractCompos

public class com/rubensousa/dpadrecyclerview/compose/DpadComposeViewHolder : com/rubensousa/dpadrecyclerview/compose/DpadAbstractComposeViewHolder {
public static final field $stable I
public fun <init> (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function5;)V
public synthetic fun <init> (Landroid/view/ViewGroup;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/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/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 Content (Ljava/lang/Object;ZZLandroidx/compose/runtime/Composer;I)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
import com.rubensousa.dpadrecyclerview.DpadViewHolder

Expand All @@ -41,7 +42,8 @@ import com.rubensousa.dpadrecyclerview.DpadViewHolder
*/
abstract class DpadAbstractComposeViewHolder<T>(
parent: ViewGroup,
isFocusable: Boolean = true
isFocusable: Boolean = true,
compositionStrategy: ViewCompositionStrategy = RecyclerViewCompositionStrategy.DisposeOnRecycled
) : RecyclerView.ViewHolder(ComposeView(parent.context)), DpadViewHolder {

private val itemState = mutableStateOf<T?>(null)
Expand All @@ -50,7 +52,7 @@ abstract class DpadAbstractComposeViewHolder<T>(

init {
val composeView = itemView as ComposeView
composeView.setViewCompositionStrategy(RecyclerViewCompositionStrategy.DisposeOnRecycled)
composeView.setViewCompositionStrategy(compositionStrategy)
composeView.isFocusable = isFocusable
composeView.isFocusableInTouchMode = isFocusable
composeView.descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.rubensousa.dpadrecyclerview.compose

import android.view.ViewGroup
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ViewCompositionStrategy

/**
* A basic implementation of [DpadAbstractComposeViewHolder]
Expand Down Expand Up @@ -44,8 +45,9 @@ open class DpadComposeViewHolder<T>(
onClick: ((item: T) -> Unit)? = null,
onLongClick: ((item: T) -> Boolean)? = null,
isFocusable: Boolean = true,
compositionStrategy: ViewCompositionStrategy = RecyclerViewCompositionStrategy.DisposeOnRecycled,
private val composable: DpadComposable<T>,
) : DpadAbstractComposeViewHolder<T>(parent, isFocusable) {
) : DpadAbstractComposeViewHolder<T>(parent, isFocusable, compositionStrategy) {

init {
if (onClick != null) {
Expand Down

0 comments on commit 51be18e

Please sign in to comment.