Skip to content

Improve picker accessibility #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ internal fun DefaultWheelTimePicker(
}
Row {
//Hour
val hoursTexts = if(timeFormat == TimeFormat.HOUR_24) hours.map { it.text } else amPmHours.map { it.text }
WheelTextPicker(
size = DpSize(
width = size.width / if(timeFormat == TimeFormat.HOUR_24) 2 else 3,
height = size.height
),
texts = if(timeFormat == TimeFormat.HOUR_24) hours.map { it.text } else amPmHours.map { it.text },
texts = hoursTexts,
contentDescriptions = hoursTexts.map { "$it:00" },
rowCount = rowCount,
style = textStyle,
color = textColor,
Expand Down Expand Up @@ -153,6 +155,7 @@ internal fun DefaultWheelTimePicker(
height = size.height
),
texts = minutes.map { it.text },
contentDescriptions = minutes.map { "${it.text}min" },
rowCount = rowCount,
style = textStyle,
color = textColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
Expand All @@ -16,22 +23,31 @@ fun WheelTextPicker(
startIndex: Int = 0,
size: DpSize = DpSize(128.dp, 128.dp),
texts: List<String>,
contentDescriptions: List<String> = emptyList(),
rowCount: Int,
style: TextStyle = MaterialTheme.typography.titleMedium,
color: Color = LocalContentColor.current,
selectorProperties: SelectorProperties = WheelPickerDefaults.selectorProperties(),
onScrollFinished: (snappedIndex: Int) -> Int? = { null },
) {
var snappedIndex by remember { mutableStateOf(startIndex) }
WheelPicker(
modifier = modifier,
startIndex = startIndex,
size = size,
count = texts.size,
rowCount = rowCount,
selectorProperties = selectorProperties,
onScrollFinished = onScrollFinished
onScrollFinished = {
snappedIndex = it
onScrollFinished(it)
}
){ index ->
Text(
modifier = Modifier.semantics {
selected = snappedIndex == index
contentDescription = contentDescriptions.getOrElse(index) { texts[index] }
},
text = texts[index],
style = style,
color = color,
Expand Down