VectorChildFinder icon indicating copy to clipboard operation
VectorChildFinder copied to clipboard

How can we use with Jetpack Compose Image?

Open orcuns opened this issue 1 year ago • 1 comments

@Composable
fun Button(style: ButtonStyle = ButtonStyle()) {
    val colorFilter = style.centerImageTintColorRes.let { ColorFilter.tint(colorRes(id = it)) }
    val imageView = ImageView(LocalContext.current)
    val vector = VectorChildFinder(LocalContext.current, style.centerImageRes, imageView)
    val path1: VectorDrawableCompat.VFullPath = vector.findPathByName("path1")
    path1.fillColor = style.centerImageTintColorRes

    imageView.drawable.toBitmap().asImageBitmap()

      Image(
            painter = painterResource(id = style.centerImageRes),
            colorFilter = colorFilter,
            contentDescription = "", modifier = Modifier.size(54.dp)
        )
}

I can't make it with Jetpack compose unfortunately. Maybe someone else knows a way to make it work?

orcuns avatar Jun 19 '23 14:06 orcuns

Hey @orcuns , sorry for the late response. Here's how to use it with Jetpack Compose:

@Composable
fun VectorPathFinderIV(){
    AndroidView(factory = {context ->
        val iv = ImageView(context)
        val vector = VectorChildFinder(context, R.drawable.baseline_add_chart_24,
            iv)
        val path1 : VectorDrawableCompat.VFullPath = vector.findPathByName("mypath1")
        path1.fillColor = Color.YELLOW
        iv
    }, update = {
        it.invalidate()
    })
}

Then call VectorPathFinderIV() to show the image.

devmike01 avatar Sep 13 '23 08:09 devmike01