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

Thierry

02/09/2020, 9:52 PM
any known issues with DrawVector?
Copy code
VectorImage(id=R.drawable.stream_tail_incoming, tint=Color.Black)
Copy code
@Composable
fun VectorImage(modifier: Modifier = Modifier.None, @DrawableRes id: Int, tint: Color = Color.Transparent) {
    val vector = vectorResource(id)
    WithDensity {
        Container(
            modifier = modifier, width=vector.defaultWidth, height=vector.defaultHeight
        ) {
            DrawVector(vector, tint)
        }
    }
}
it doesn't show up at all in the preview
(on beta4)
the same/or similar code seems to work fine in beta 3
s

Simon Schubert

02/09/2020, 11:52 PM
Copy code
@Composable
fun VectorImage(
    modifier: Modifier = Modifier.None, @DrawableRes id: Int,
    tint: Color = Color.Transparent
) {
    val vector = vectorResource(id)
    WithDensity {
        Container(
            modifier = modifier + LayoutSize(vector.defaultWidth, vector.defaultHeight)
        ) {
            DrawVector(vector, tint)
        }
    }
}
This works for me on dev04
j

jolo

02/10/2020, 7:40 AM
Do you have this in your gradle file? composeOptions {     kotlinCompilerExtensionVersion “0.1.0-dev04”   } It’s not added automatically for you, and without it your images won’t work 😅
t

Thierry

02/10/2020, 3:04 PM
Turns out that it's drawing the drawable, but makes it so small that it's barely visible. I'm not quite sure yet why this happens
PS. cool to see another dutch startup here
note the red pixel bottom right
the red dot is caused by this drawable
Copy code
<vector xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:viewportWidth="25"
    android:viewportHeight="26"
    android:width="25dp"
    android:height="26dp">
    <group
        android:translateX="-274"
        android:translateY="-152">
        <group
            android:translateX="251"
            android:translateY="145">
            <path
                android:pathData="M46.891359 6.98775263C48.9803761 11.4859833 47.7147563 15.565241 46.3806948 17.9902209C45.0465335 20.4152008 42.4982945 22.7020908 40.5 26.2043725C39.167837 28.5391937 38.9979804 31 38.9979804 33C37.3571807 30.011653 35.2609596 27.7464773 32.5727539 26.2043725C29.8844483 24.6622678 26.3289084 23.9254878 23.0601981 23.9941325"
                android:fillColor="#000000"
                android:fillAlpha="1" />
        </group>
    </group>
</vector>