https://kotlinlang.org logo
#compose
Title
# compose
j

james

03/04/2023, 12:51 AM
Has anyone had problems with
ImageVector
being remembered incorrectly? I’d like to know if this is a bug in
rememberVectorPainter()
or if I’m just doing something silly. See thread for details 🧵 ➡️
Consider the following code:
Copy code
val icon = if (selected) MyIcon.Selected else MyIcon.Normal
val color = if (selected) Color.Green else Color.Black
Icon(
    modifier = Modifier.size(48.dp),
    imageVector = icon,
    tint = color,
    contentDescription = null,
)
MyIcon.Normal
and
MyIcon.Selected
are both `ImageVector`s with identical `Path`s but different line stroke widths, and the
name
argument provided to the builder is different for each of them too. The problem I’m having is that code doesn’t update the icon when the
selected
variable changes. The colour updates as expected but the image itself doesn’t, it continues to
remember
the
Normal
version 🤔
I’ve tested it in reverse too — if I start with the
Selected
version for initial composition and then switch to
Normal
, it doesn’t change
m

myanmarking

03/04/2023, 6:22 PM
Maybe the problem is related to the selected boolean. Print it to check if it actually changes or paste the full code
j

james

03/04/2023, 11:43 PM
That was the first thing I checked 😅 I’ve verified the boolean is all good, in fact I debugged and set a point to print the
name
field of the
ImageVector
and I see the change occur there
12 Views