JengaWheelPicker

fun <T> JengaWheelPicker(items: List<T>, selectedIndex: Int, onSelectedIndexChange: (Int) -> Unit, modifier: Modifier = Modifier, itemLabel: (T) -> String = { it.toString() }, contentDescription: String? = null, visibleItemCount: Int = JengaWheelPickerDefaults.VisibleItemCount, itemHeight: Dp = JengaWheelPickerDefaults.ItemHeight, selectionShape: Shape = JengaWheelPickerDefaults.selectionShape, textStyle: TextStyle = JengaWheelPickerDefaults.textStyle, colors: JengaWheelPickerColors = JengaWheelPickerDefaults.colors(), itemContent: @Composable (item: T, selected: Boolean) -> Unit = { item, selected -> JengaText( text = itemLabel(item), style = textStyle, color = if (selected) colors.selectedContent else colors.content, maxLines = 1, ) })(source)

A scroll wheel for picking one of items: rows scroll vertically and snap so one sits in the highlighted middle band. Tapping a row scrolls it into the middle. For accessibility the wheel is a single adjustable control whose value is the selected row's label.

Parameters

items

the options.

selectedIndex

the index of the selected option.

onSelectedIndexChange

called with the new index once the wheel settles.

modifier

the Modifier for the wheel.

itemLabel

the text for an option, also announced by screen readers.

contentDescription

accessibility label for the wheel (e.g. "Year").

visibleItemCount

the number of rows visible at once; a positive odd number.

itemHeight

the height of each row.

selectionShape

the shape of the middle band.

textStyle

the row text style.

colors

the color set; defaults to JengaWheelPickerDefaults.colors.

itemContent

the content of a row, given the option and whether it is selected.

Samples

var index by remember {
    mutableIntStateOf(
        value = 0,
    )
}
JengaWheelPicker(
    items = listOf(
        "Morning",
        "Afternoon",
        "Evening",
    ),
    selectedIndex = index,
    onSelectedIndexChange = { index = it },
)