Can we somehow simplify this? ``` i...
# compose
a
Can we somehow simplify this?
Copy code
if (enabled) {
                    Icon(
                        painter = painterResource(id = iconId),
                        contentDescription = null,
                        modifier = Modifier.size(32.dp),
                        tint = iconColor
                    )
                } else {
                    Icon(
                        painter = painterResource(id = iconId),
                        contentDescription = null,
                        modifier = Modifier.size(32.dp),
                    )
                }
I am trying something along these lines
Copy code
Icon(
                        painter = painterResource(id = iconId),
                        contentDescription = null,
                        modifier = Modifier.size(32.dp),
                        tint = if (enabled) iconColor else ...
                    )
m
You can copy the default value from
Icon
for tint for the else part.
Copy code
LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
a
That's possible. But my code has to change if that default value changes in future. Probably this is more of a kotlin question
if (enabled) myvalue else [default value whatever it is]
j
But my code has to change if that default value changes in future.
That doesn't make much sense. Changing the default value would be breaking change so I wouldn't expect that happening. And if it will change, having it overriden is actually better for you, because your ui stays the same which is probably intended... Anyway, if you really want it that way, your best option now is to create your own Icon composable with nullable tintColor which will call the default Icon with or without tintColor...
a
That doesn't make much sense. Changing the default value would be breaking change so I wouldn't expect that happening. And if it will change, having it overriden is actually better for you, because your ui stays the same which is probably intended...
This is a good point. Probably i was more thinking why to find the default color from library and put it in my code.
I was also thinking of putting
Copy code
else Color.Unspecified,
but that looks like taking a different path than
Copy code
LocalContentColor.current.copy(alpha = LocalContentAlpha.current)