Skip to content

Picker ​

A single-column bottom wheel picker. When scrolling stops, the item closest to the center indicator is the selected one.

Spec source: lh-ui-core/specs/picker.json · Golden cases: cases/picker.json (13 cases; clamping and token mappings translated into JVM unit tests, scrolling, button interactions and label semantics translated into Compose UI Test)

Usage ​

It pops up from the bottom: the overlay on top, the panel below (with rounded top corners). The toolbar has three parts: cancel / title / confirm.

9:41Picker
Select
Option 1
Option 2
Option 3

HTML mock preview (Android / Compose look), not an on-device render

kotlin
var visible by remember { mutableStateOf(false) }
var value by remember { mutableStateOf(0) }
val options = listOf("选项一", "选项二", "选项三")
LhPicker(
  visible = visible,
  options = options,
  onValueChange = { value = it },
  onConfirm = { value = it; visible = false },
  onCancel = { visible = false },
  onClose = { visible = false },
  value = value,
  title = "请选择",
)

Selection mechanism ​

The wheel is a scrollable list where every item is picker.itemHeight tall; the center indicator is two horizontal lines spaced one itemHeight apart. After scrolling stops, the scrolled distance is rounded to derive the selected index, and onValueChange fires when it changes. When value is out of range, LhPickerDefaults.clamp clamps it into the candidate range.

API ​

Props ​

PropDescriptionTypeDefault
visibleWhether the picker is shown; when false, nothing is renderedBoolean—
optionsArray of candidate item texts (single column)List<String>—
onValueChangeTriggered when the wheel stops and the selected item changes, carrying the new index(Int) -> Unit—
onConfirmTriggered when the confirm button is tapped, carrying the currently selected index(Int) -> Unit—
onCancelTriggered when the cancel button is tapped() -> Unit—
onCloseTriggered after confirm / cancel; the host uses this to set visible to false() -> Unit—
valueIndex of the selected item (0-based); clamped when out of rangeInt0
titleTitle in the middle of the toolbar; falls back to the locale pack when omitted (default "Please select"), empty string renders no title nodeString@lh-i18n
confirmTextConfirm button text; falls back to the locale pack when omittedString@lh-i18n
cancelTextCancel button text; falls back to the locale pack when omittedString@lh-i18n
contentWheel content area (overrides the default candidate rendering; the spec's default slot)@Composable ((List<String>, Int) -> Unit)?null
toolbarToolbar (overrides the default confirm / title / cancel; the spec's toolbar slot)@Composable (() -> Unit)?null
listStateWheel list state (provided by default via rememberLhPickerListState(value, options); can be injected from the outside in tests)LazyListStatesee left
modifierModifier (applied to the panel)ModifierModifier

Test hook: rememberLhPickerListState(value, options) returns a LazyListState initially positioned at value; instrumented tests can use listState.dispatchRawDelta(...) to drive the scroll deterministically.

Token reference ​

TokenUsage
picker.heightPanel height (260dp)
picker.itemHeightItem height (40dp; also the center indicator spacing)
picker.toolbarHeightToolbar height (44dp)
picker.itemFontSizeCandidate item font size
picker.borderRadiusPanel top corner radius
picker.paddingHorizontalPanel horizontal padding (follows spacing.md)
zIndex.modal / zIndex.modalBackdropLayering semantics alignment (the Compose Popup provides window-level layering on its own)
color.background.overlayOverlay color
color.background.defaultPanel background color
color.text.primary / color.text.regularTitle / candidate item color
color.border.lighterCenter indicator line color
color.primary.defaultConfirm button color

Golden case reference ​

case idAssertionLocal test
confirm-emits-onconfirm-with-valueConfirm carries the current index + onCloseLhPickerTest.confirm_emits_onConfirm_with_value_and_onClose (Compose UI Test)
confirm-also-emits-oncloseConfirm also triggers onClosesame as above
cancel-emits-oncancelCancel triggers onCancel + onCloseLhPickerTest.cancel_emits_onCancel_and_onClose
scroll-emits-onvaluechangeScrolling changes the selection and triggers onValueChangeLhPickerTest.scroll_emits_onValueChange
clamp-negative-value-to-zeroA negative value is clamped to 0LhPickerDefaultsTest.clamp_negative_value_to_zero
clamp-overflow-value-to-lastAn out-of-range value is clamped to the last itemLhPickerDefaultsTest.clamp_overflow_value_to_last
title-renders-textThe title renders textLhPickerTest.title_renders_text
hidden-not-renderedWhen hidden, nothing is renderedLhPickerTest.hidden_is_not_rendered
confirm-text-fallback-localeAn omitted confirm label falls back to the locale packLhPickerTest.confirm_text_falls_back_to_locale
cancel-text-fallback-localeAn omitted cancel label falls back to the locale packLhPickerTest.cancel_text_falls_back_to_locale
confirm-text-explicit-winsAn explicit confirm label takes precedence over the locale packLhPickerTest.confirm_text_explicit_wins
title-fallback-localeAn omitted title falls back to the locale pack (default "Please select")LhPickerTest.title_falls_back_to_locale
title-empty-hides-nodeAn empty title renders no title nodeLhPickerTest.title_empty_hides_node
bash
./gradlew :components:picker:test                                # JVM part
./gradlew :components:picker:connectedAndroidTest               # Interaction part (requires a device)

lh-ui native bloodline · Android (Kotlin + Compose)