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

nglauber

11/05/2019, 1:51 AM
Last week I saw a question regarding
DrawVector
alignment. I’m not sure if it is related but, I’m trying to do this:
Copy code
FloatingActionButton(
    onClick = { ... }
) {
    DrawVector(+vectorResource(R.drawable.ic_baseline_add))
}
The icon (which is an
vector
drawable) is aligned on the top left. And using this code is throwing an exception.
Copy code
FloatingActionButton(
    icon = imageFromResource(resources, R.drawable.ic_baseline_add),
    onClick = { ... }
)
My suggestion would be: 1) the
icon
parameter supports a
vector
drawable; or 2)
Image
component supports a
vector
drawable.
a

Andrey Kulikov

11/05/2019, 11:35 AM
Thanks! We have it in our roadmap, some unified components which works with both bitmaps and vectors and so you could be able to provide both into such slots. Also we have a bug for imageFromResource to improve the behavior about this exception. For now you can use another overload of FloatingActionButton which accepts children: @Composable() () -> Unit. this allows you to pass any content you want inside the FAB, for example vectors
n

nglauber

11/05/2019, 12:36 PM
Thanks @Andrey Kulikov! I think it is the first one I mentioned, isn’t it? The problem with it is: I can’t align the icon inside the FAB
a

Andrey Kulikov

11/05/2019, 1:04 PM
yeah, the variant you had, but with some modifications.
you need to add centering, we can do it like this right now
Wrap(alignment = Alignment.Center) { Container(width = 24.dp, height = 24.dp) { DrawVector(+vectorResource(R.drawable.myId)) } }
n

nglauber

11/05/2019, 3:26 PM
it worked 😉 thanks @Andrey Kulikov
2 Views