-
-
Save eevajonnapanula/69a5add9fce5c53758544b61bec8129b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SwitchRow( | |
text: String, | |
checked: Boolean, | |
onChange: (Boolean) -> Unit | |
) { | |
Row( | |
modifier = Modifier | |
.fillMaxWidth() | |
// We add the toggleable modifier | |
// with the state (value) and role | |
.toggleable( | |
value = checked, | |
role = Role.Switch, | |
onValueChange = { onChange(it) }, | |
) | |
.padding(16.dp), | |
horizontalArrangement = Arrangement.SpaceBetween, | |
verticalAlignment = Alignment.CenterVertically, | |
) { | |
Text( | |
text = text, | |
style = MaterialTheme.typography.labelLarge, | |
color = MaterialTheme.colorScheme.onPrimaryContainer | |
) | |
Switch( | |
checked = checked, | |
onCheckedChange = { onChange(it) }, | |
// We clear the semantics | |
modifier = Modifier.clearAndSetSemantics {} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment