Created
December 29, 2023 15:25
-
-
Save ngallazzi/1544a9817d94b8071490ff3a9d24f7df to your computer and use it in GitHub Desktop.
Switch layout
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 SwitchLayout() { | |
val context = LocalContext.current | |
var status: SwitchStatus by remember { | |
mutableStateOf(SwitchStatus.OFF) | |
} | |
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(32.dp)) { | |
Image( | |
modifier = Modifier | |
.width(196.dp) | |
.semantics { | |
contentDescription = | |
context.getString(R.string.pacman_lamp_image_description) | |
drawableId = status.imageRes | |
}, | |
painter = painterResource(id = status.imageRes), | |
contentDescription = stringResource(R.string.pacman_lamp_image_description) | |
) | |
Spacer(modifier = Modifier.height(16.dp)) | |
Text("Status is: ${status.name}", modifier = Modifier.semantics { | |
contentDescription = context.getString(R.string.current_status_description) | |
}, style = MaterialTheme.typography.headlineMedium) | |
Spacer(modifier = Modifier.height(16.dp)) | |
Row { | |
Button( | |
enabled = status == SwitchStatus.ON, | |
onClick = { status = SwitchStatus.OFF }, | |
modifier = Modifier.semantics { | |
contentDescription = | |
context.getString(R.string.off_button_description) | |
}) { | |
Text(SwitchStatus.OFF.name) | |
} | |
Spacer(modifier = Modifier.width(32.dp)) | |
Button( | |
enabled = status == SwitchStatus.OFF, | |
onClick = { status = SwitchStatus.ON }, | |
modifier = Modifier.semantics { | |
contentDescription = | |
context.getString(R.string.on_button_description) | |
}) { | |
Text(SwitchStatus.ON.name) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment