Skip to content

Instantly share code, notes, and snippets.

@takahirom
Last active December 4, 2021 09:37
Show Gist options
  • Save takahirom/d4fd5cf087886f7034fef57ca3d2c2f1 to your computer and use it in GitHub Desktop.
Save takahirom/d4fd5cf087886f7034fef57ca3d2c2f1 to your computer and use it in GitHub Desktop.
@Composable
fun Screen() {
// State has only on Screen
var checked by remember { mutableStateOf(false) }
Row {
MySwitch(checked = checked, onCheckChanged = { checked = it })
Text(
text = if (checked) "on" else "false",
Modifier.clickable {
checked = !checked
}
)
}
}
// checked is Immutable, a value that cannot be changed.
@Composable
fun MySwitch(checked: Boolean, onCheckChanged: (Boolean) -> Unit) {
Switch(
checked = checked,
onCheckedChange = {
onCheckChanged(it)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment