Stylianos Gakis
05/29/2023, 9:50 AM<selector>
to decide on the fillColor
and the strokeColor
for some drawable depending on if state_checked
is true or not.
For Compose, is there a way I can forward that information to the drawable? Using painterResource(R.drawable.foo)
to bring that in atm which doesn’t have any parameter for it, but maybe there’s some other way? 👀Stylianos Gakis
05/29/2023, 9:50 AMJoel Denke
05/29/2023, 11:51 AMJoel Denke
05/29/2023, 11:52 AMval interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val color = if (isPressed) Color.Blue else Color.Green
Stylianos Gakis
05/30/2023, 1:00 PMpainterResource()
. Had to do that for dark mode since our SVG was not built properly enough to support using tint to color it (it had a color on top of a color, but tint only supports 1 color + different alpha values).
Not that fun, but it works, and if I ever get a proper SVG then this could be 2 xmls, just for active/not active.
Btw this exists https://github.com/DevSrSouza/svg-to-compose for something like you described, but I didn’t want to overcomplicate this for myselfJoel Denke
05/30/2023, 1:17 PMStylianos Gakis
05/30/2023, 1:22 PMIcon()
composable, you get a tint
parameter. That tint color is applied to the entire vector fully.
Our vector image was this helipad looking vector. How it’s drawn is that there’s one vector which is the circle behind, and then the H is 3 lines on top of it. [pic attached]
With the tint applying its color to anything, we simply got a circle with all of it being the same circle.
If the vector instead was the circle, and the H inside was done using transparency then it’d work, since it’d not apply any color there.
Initially I thought maybe there’s a way to “subtract” a path from another to build the transparent center like that, but didn’t find a way.
But I have absolutely no idea how to do something like this in Figma either, so I gave up and said let’s use different XML files with hard-coded colors so that it fits all cases 😅Joel Denke
05/30/2023, 1:37 PMStylianos Gakis
05/30/2023, 3:22 PM