DpadComposeViewHolder

class DpadComposeViewHolder<T>(parent: ViewGroup, onClick: (item: T) -> Unit? = null, onLongClick: (item: T) -> Boolean? = null, isFocusable: Boolean = true, content: @Composable (item: T, isFocused: Boolean) -> Unit = { _, _ -> }) : RecyclerView.ViewHolder

Deprecated

Use DpadComposeFocusViewHolder instead

A basic ViewHolder that forwards content to a ComposeView and handles focus and clicks inside the View system.

Focus is kept inside the internal ComposeView to ensure that it behaves correctly and to workaround the following issues:

  1. Focus is not sent correctly from Views to Composables: b/268248352 This is solved by just holding the focus in ComposeView

  2. Clicking on a focused Composable does not trigger the standard audio feedback: b/268268856 This is solved by just handling the click on ComposeView directly

This allows inline definition of ViewHolders in onCreateViewHolder:

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DpadComposeViewHolder<Int> {
return DpadComposeViewHolder(parent) { item, isFocused ->
ItemComposable(item, isFocused)
}
}

To update the current item, override onBindViewHolder and call setItemState:

override fun onBindViewHolder(holder: DpadComposeViewHolder<Int>, position: Int) {
holder.setItemState(getItem(position))
}

Constructors

Link copied to clipboard
constructor(parent: ViewGroup, onClick: (item: T) -> Unit? = null, onLongClick: (item: T) -> Boolean? = null, isFocusable: Boolean = true, content: @Composable (item: T, isFocused: Boolean) -> Unit = { _, _ -> })

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun getItem(): T?
Link copied to clipboard
fun setContent(content: @Composable (item: T) -> Unit)
Link copied to clipboard
fun setIsRecyclable(recyclable: Boolean)
Link copied to clipboard
fun setItemState(item: T?)