Peter
10/01/2024, 10:54 AMText()
color by using ColorFilter
?Khanzada Kashif
10/01/2024, 1:46 PMPeter
10/01/2024, 2:34 PManimateColorAsState()
.
@Composable
private fun Item(
@DrawableRes icon: Int,
@StringRes text: Int,
isSelected: Boolean,
) {
Column {
ItemIcon(icon = icon, isSelected = isSelected)
ItemText(text = text, isSelected = isSelected)
}
}
@Composable
private fun ItemIcon(@DrawableRes icon: Int, isSelected: Boolean) {
val overlayColor by animateColorAsState(
targetValue = if (isSelected) Color.Transparent else AppColor.grey50,
label = "icon filter color",
)
val colorFilter = remember(overlayColor) {
ColorFilter.tint(overlayColor, BlendMode.SrcAtop)
}
Image(
painter = painterResource(icon),
contentDescription = null,
colorFilter = colorFilter,
)
}
@Composable
private fun ItemText(@StringRes text: Int, isSelected: Boolean) {
val color by animateColorAsState(
targetValue = if (isSelected) AppColor.blueBrand else AppColor.grey50,
label = "item text color",
)
Text(text = stringResource(text), color = color)
}
Peter
10/01/2024, 2:36 PMisSelected
states:Khanzada Kashif
10/01/2024, 2:58 PMPeter
10/01/2024, 4:10 PMKhanzada Kashif
10/01/2024, 4:18 PMPeter
10/01/2024, 4:41 PMKhanzada Kashif
10/01/2024, 5:10 PM@Composable
private fun Item(
@DrawableRes icon: Int,
@StringRes text: Int,
isSelected: Boolean,
) {
val imageColor by animateColorAsState(
targetValue = if (isSelected) Color.Transparent else AppColor.grey50,
label = "icon filter color",
)
val textColor by animateColorAsState(
targetValue =if (isSelected) AppColor.blueBrand else AppColor.grey50,
label = "item text color",
)
Column {
ItemIcon(icon = icon, color = imageColor)
ItemText(text = text, color = textColor)
}
}
@Composable
private fun ItemIcon(@DrawableRes icon: Int, color: Color) {
Image(
painter = painterResource(icon),
contentDescription = null,
colorFilter = ColorFilter.tint(color, BlendMode.SrcAtop)
)
}
@Composable
private fun ItemText(@StringRes text: Int, color: Color) {
Text(text = stringResource(text), color = color)
}
Peter
10/01/2024, 7:55 PManimateColorAsState
.
Something as following, but I have no idea how to set ColorFilter
to my Text
color.
@Composable
private fun Item(
@DrawableRes icon: Int,
@StringRes text: Int,
isSelected: Boolean,
) {
Column {
val overlayColor by animateColorAsState(
targetValue = if (isSelected) Color.Transparent else AppColor.grey50,
label = "icon filter color",
)
val colorFilter = remember(overlayColor) {
ColorFilter.tint(overlayColor, BlendMode.SrcAtop)
}
Image(
painter = painterResource(icon),
contentDescription = null,
colorFilter = colorFilter,
)
Text(
text = stringResource(text),
// Set default color like this or something:
color = AppColor.blueBrand,
// Not sure how to combine [colorFilter] and [AppColor.blueBrand]
)
}
}
Khanzada Kashif
10/02/2024, 5:26 AM