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

Miguel A. Ruiz

03/19/2020, 9:26 PM
Hi, what is the proper way to paint a Vectorial images in the version dev07?
p

pula

03/19/2020, 9:52 PM
Copy code
@Composable
fun VectorImage(
    modifier: Modifier = Modifier.None,
    @DrawableRes id: Int,
    tint: Color = Color.Transparent
) {
    val vector = vectorResource(id)
    Container(
        modifier = modifier + LayoutSize(vector.defaultWidth, vector.defaultHeight)
    ) {
        DrawVector(vector, tint)
    }
}
is the way its been done most recently, not sure if that changed in dev07
m

Miguel A. Ruiz

03/19/2020, 10:05 PM
thanks, but this is what I had in dev06, as I read now we have to use drawVector modifier. I have tried and this work but I need a "view" which doesn't need children
Copy code
@Composable
fun SimpleVector(@DrawableRes id: Int, tint: Color = Color.Transparent) {
    val vector = vectorResource(id)
    Container(
        width = vector.defaultWidth,
        height = vector.defaultHeight,
        modifier = drawVector(vector, tint)
    ) {
        Text("")
    }
}
This works for me but it is a hack
I need to use this modifier in a component which don't need children to get rid of this empty Text
it looks like VectorPainter will replace drawVector but i think thats for dev08
because that deprecation warning doesnt show up for me in AS
with dev07
m

Miguel A. Ruiz

03/19/2020, 10:13 PM
ok, so I will have to wait to dev08
l

Leland Richardson [G]

03/19/2020, 10:15 PM
why do you need the empty text?
does something break without it?
m

Miguel A. Ruiz

03/19/2020, 10:16 PM
because the container require a children
but I know this is really ugly
l

Leland Richardson [G]

03/19/2020, 10:16 PM
oh i forgot container was gross like that
in general this is not the case
just use
Box
it is the Container replacement, and there are no requirements on number of chuldren
Container will be deprecated in dev08
m

Miguel A. Ruiz

03/19/2020, 10:23 PM
this is working like a charm
thanks guys
4 Views