One thing you can improve is a11y support. For example in a switch preference, instead of
Modifier.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
)
}