Skip to content

TimePicker ​

TimePicker is a basic interactive component in COUI used for selecting a time of day with hour and minute scroll wheels, mirroring ColorOS's COUITimeLimitPicker. It supports both 24-hour and 12-hour formats; in 12-hour mode an AM/PM wheel is added, placed before the hour wheel or after the minute wheel depending on locale convention. Optional unit labels (e.g. "h" / "min") can be drawn beside the selected row like the COUI unit text.

Times are represented by the plain TimeValue data class; the hour is always stored in 24-hour form (0..23) regardless of the display mode.

Import ​

kotlin
import io.github.suqi8.coui.kmp.basic.TimePicker
import io.github.suqi8.coui.kmp.basic.TimePickerDefaults
import io.github.suqi8.coui.kmp.basic.TimeValue

Basic Usage ​

kotlin
var time by remember { mutableStateOf(TimeValue(hour = 16, minute = 30)) }

TimePicker(
    value = time,
    onValueChange = { time = it }
)

Component States ​

12-Hour Format ​

When is24Hour is false, hours display as 1..12 and an AM/PM wheel is shown after the minute wheel.

kotlin
TimePicker(
    value = time,
    onValueChange = { time = it },
    is24Hour = false
)

Disabled State ​

kotlin
TimePicker(
    value = time,
    onValueChange = { time = it },
    enabled = false
)

Properties ​

TimePicker Properties ​

Property NameTypeDescriptionDefault ValueRequired
valueTimeValueCurrently selected time (hour always in 24-hour form)-Yes
onValueChange(TimeValue) -> UnitCallback invoked when the selected time changes-Yes
modifierModifierModifier applied to the pickerModifierNo
enabledBooleanWhether the picker is enabled for user interactiontrueNo
is24HourBooleanWhether the hour wheel uses the 24-hour formattrueNo
amPmFirstBooleanWhether the AM/PM wheel is placed before the hour wheelfalseNo
amLabelStringDisplay string for AM on the AM/PM wheelTimePickerDefaults.AmLabelNo
pmLabelStringDisplay string for PM on the AM/PM wheelTimePickerDefaults.PmLabelNo
hourUnitStringUnit label beside the selected hour; empty to hideTimePickerDefaults.HourUnitNo
minuteUnitStringUnit label beside the selected minute; empty to hideTimePickerDefaults.MinuteUnitNo
hourColumnWidthDpWidth of the hour columnTimePickerDefaults.HourColumnWidthNo
minuteColumnWidthDpWidth of the minute columnTimePickerDefaults.MinuteColumnWidthNo
amPmColumnWidthDpWidth of the AM/PM columnTimePickerDefaults.AmPmColumnWidthNo
colorsNumberPickerColorsColor configuration of the wheelsNumberPickerDefaults.colors()No
textStyleTextStyleText style for the wheel itemsCOUITheme.textStyles.title3No
itemHeightDpThe height of each wheel itemNumberPickerDefaults.ItemHeightNo
insideMarginPaddingValuesPadding around the wheel columnsTimePickerDefaults.InsideMarginNo

TimeValue Class ​

Property NameTypeDescription
hourIntThe hour of the day in 24-hour form (0..23)
minuteIntThe minute of the hour (0..59)

TimePickerDefaults Object ​

Property NameTypeDescriptionDefault Value
HourColumnWidthDpDefault width of the hour column76.dp
MinuteColumnWidthDpDefault width of the minute column76.dp
AmPmColumnWidthDpDefault width of the AM/PM column62.dp
InsideMarginPaddingValuesDefault padding around the wheel columnsPaddingValues(vertical = 12.dp)
UnitTextOffsetDpOffset of the unit label from the wheel center13.dp
UnitFontSizeTextUnitFont size of the unit label14.sp
AmLabelStringDefault AM label"AM"
PmLabelStringDefault PM label"PM"
HourUnitStringDefault hour unit label (hidden)""
MinuteUnitStringDefault minute unit label (hidden)""

Advanced Usage ​

Unit Labels ​

Draw unit labels beside the selected hour and minute, like the COUI picker:

kotlin
TimePicker(
    value = time,
    onValueChange = { time = it },
    hourUnit = "h",
    minuteUnit = "min"
)

Localized 12-Hour Picker ​

For locales whose time pattern starts with the day period (e.g. Chinese), place the AM/PM wheel first and localize its labels:

kotlin
TimePicker(
    value = time,
    onValueChange = { time = it },
    is24Hour = false,
    amPmFirst = true,
    amLabel = "上午",
    pmLabel = "下午",
    hourUnit = "时",
    minuteUnit = "分"
)

Custom Colors ​

kotlin
TimePicker(
    value = time,
    onValueChange = { time = it },
    colors = NumberPickerDefaults.colors(
        selectedTextColor = Color.Red,
        unselectedTextColor = Color.Gray
    )
)

Changelog

Released under the Apache-2.0 License