rememberListItemRenderer

@Composable
inline fun <T : Any> rememberListItemRenderer(noinline content: @Composable ListItemScope.(item: T) -> Unit): ListCellRenderer<*>

Remembers the renderer that stamps content for every item of a component it is installed on, captured against the enclosing composition so the cell sees the state and androidx.compose.runtime.CompositionLocals around this call.

The renderer is stable across recompositions - a fresh content lambda each pass is honored without rebuilding anything - and it stamps nothing once the composition that remembered it is disposed, so install it on a component whose own declaration stands in that composition rather than holding it past one.

One reused composition stamps every row, so a cell is display-only: it composes a single component, and state remembered inside it belongs to no particular row.

An item the component's model holds that is not a T throws IllegalStateException naming both types, out of the widget's own layout rather than out of composition. Nothing ties T to the model, so the two are the caller's to keep in step.

A value a JComboBox stamps its display area with - for an editable one, the text typed into its editor - composes no cell unless it is one of the model's items or a T.

A call site that cannot reify T names the item type through the overload that takes it.

Return

the renderer, to install on a component with listItemRenderer.

Parameters

content

the composable cell body, invoked with the ListItemScope and the item.


@Composable
fun <T : Any> rememberListItemRenderer(itemType: KClass<T>, content: @Composable ListItemScope.(item: T) -> Unit): ListCellRenderer<*>

Remembers the renderer that stamps content for every item of a component it is installed on, for a caller who names itemType rather than letting the call site reify it - a generic component of their own, whose item type is a type parameter and so is erased by the time this call is compiled.

Otherwise as rememberListItemRenderer taking only a cell body.

Return

the renderer, to install on a component with listItemRenderer.

Parameters

itemType

the item type content is written over, which every item a stamp hands over is checked against.

content

the composable cell body, invoked with the ListItemScope and the item.