Skip to content

Instantly share code, notes, and snippets.

@veroanggra
Created April 4, 2023 03:10
Show Gist options
  • Save veroanggra/d43429c28bb51f3fb52be9bf305d4b8d to your computer and use it in GitHub Desktop.
Save veroanggra/d43429c28bb51f3fb52be9bf305d4b8d to your computer and use it in GitHub Desktop.
@Composable
fun FavoriteButton(modifier: Modifier = Modifier) {
val (favorite, setFavorite) = remember {
mutableStateOf(false)
}
val (color, setColor) = remember {
mutableStateOf(Color.Gray)
}
setColor(
if (favorite) {
Color.Red
} else {
Color.Gray
}
)
Image(Icons.Default.Favorite,
contentDescription = null,
colorFilter = ColorFilter.tint(color),
modifier = modifier
.size(200.dp)
.clickable {
setFavorite(!favorite)
if (color == Color.Red) {
setFavorite(!favorite)
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment