https://kotlinlang.org logo
c

carbaj0

01/27/2020, 2:58 PM
Copy code
+imageResource(R.drawable.ic_arrow_core_lines_white)
do Compose support vectors?
g

gpaligot

01/27/2020, 3:09 PM
Yes,
Copy code
+vectorResource(id)
But there isn't yet a
SimpleVector
Composable function.
Find here an example of a custom Composable function for vectors:
Copy code
@Composable
fun SimpleVector(@DrawableRes id: Int, tint: Color = Color.Transparent) {
    val vector = +vectorResource(id)
    WithDensity {
        Container(
            width = vector.defaultWidth.toDp(),
            height = vector.defaultHeight.toDp()
        ) {
            DrawVector(vector, tint)
        }
    }
}
c

carbaj0

01/27/2020, 3:12 PM
👍
i want to return an image like imageResource, it is possible?
a

Andrey Kulikov

01/27/2020, 4:39 PM
vectors are not images. there is a special type we return from vectorResource(id). how do you want to use it so you wanted Image?
c

carbaj0

01/27/2020, 5:23 PM
i have a drawable that is a vector, i want to retrieve it from the resources and pass it as a parameter to a component that requires an Image
a

Andrey Kulikov

01/28/2020, 1:57 PM
unfortunately currently you can't pass it as an Image. We are working on a Painter api which will allow this. But currently you should be able to directly use vectors if there is a slot api for the the composable you are using. for example for FloatingActionButton there are two overloads, one with Image param and the second one with a Composable children
👍 2
2 Views