Has anyone used 9-patch images in Compose? I'm str...
# compose
d
Has anyone used 9-patch images in Compose? I'm struggling to find a working solution for a button's background which would wrap the text's content width.
l
We did something like this:
Copy code
internal fun Modifier.viewFinderFrameDrawable(context: Context) = drawBehind {
    drawIntoCanvas {
        val scannerFrameDrawable = AppCompatResources.getDrawable(context, drawable.sc_scanner_frame)
        scannerFrameDrawable?.run {
            bounds = graphicsRect(0, 0, size.width.toInt(), size.height.toInt())
            draw(it.nativeCanvas)
        }
    }
}
❤️ 1
👍🏻 1
This draws 4 edges of a camera viewfinder like this:
Example usage (in our case):
Copy code
Box(
            Modifier
                .viewFinderFrameDrawable(LocalContext.current)
                .fillMaxWidth()
                .aspectRatio(2f)
                .align(Alignment.Center)
            )
d
Thanks a ton!
👍 1