Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we use with Jetpack Compose Image? #19

Open
orcuns opened this issue Jun 19, 2023 · 1 comment
Open

How can we use with Jetpack Compose Image? #19

orcuns opened this issue Jun 19, 2023 · 1 comment

Comments

@orcuns
Copy link

orcuns commented Jun 19, 2023

@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?

@devmike01
Copy link
Contributor

devmike01 commented Sep 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants