Created
April 4, 2023 03:10
-
-
Save veroanggra/d43429c28bb51f3fb52be9bf305d4b8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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