alorma
10/01/2021, 4:12 PMAlbert Chang
10/01/2021, 4:45 PMModifier.clickable()
, you should use Modifier.toggleable()
for better a11y support. Here’s the switch preference component I’m using in my project:
@Composable
fun SwitchPreferenceItem(
title: String,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
icon: ImageVector? = null,
secondaryText: String? = null,
enabled: Boolean = true
) {
PreferenceItem(
modifier = modifier.toggleable(
value = checked,
enabled = enabled,
onValueChange = onCheckedChange,
role = Role.Switch
),
text = { Text(text = title) },
icon = iconComposable(icon),
secondaryText = textComposable(secondaryText),
trailing = {
Switch(checked = checked, onCheckedChange = null, enabled = enabled)
},
enabled = enabled
)
}
alorma
10/01/2021, 8:27 PMMichael Paus
10/02/2021, 9:23 AMalorma
10/02/2021, 11:38 AM