Jenga Wheel Picker
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.
selected Index
the index of the selected option.
on Selected Index Change
called with the new index once the wheel settles.
modifier
the Modifier for the wheel.
item Label
the text for an option, also announced by screen readers.
content Description
accessibility label for the wheel (e.g. "Year").
visible Item Count
the number of rows visible at once; a positive odd number.
item Height
the height of each row.
selection Shape
the shape of the middle band.
text Style
the row text style.
colors
the color set; defaults to JengaWheelPickerDefaults.colors.
item Content
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 },
)Content copied to clipboard