Skip to content

Instantly share code, notes, and snippets.

@eevajonnapanula
Created July 11, 2023 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevajonnapanula/69a5add9fce5c53758544b61bec8129b to your computer and use it in GitHub Desktop.
Save eevajonnapanula/69a5add9fce5c53758544b61bec8129b to your computer and use it in GitHub Desktop.
@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