How to achieve crossed line `Text()` in case when ...
# compose
a
How to achieve crossed line
Text()
in case when text could be any size (multiple lines too)?
drawLine(maxWidth, maxHeight)
won’t work for me, cause it increase
Box
with
Text
to full screen. Maybe possible to measure text and then drawLine?
1
j
maybe with intrinsics API
n
I have made a composable which can cross out any content. It uses the drawWithContent modifier :
Copy code
@Composable
fun CrossedLine(content: @Composable () -> Unit) {
    Box(
        modifier = Modifier
            .drawWithContent {
                //Draw the content before the line
                //You can put this line after the scale block to put the line behind
                //(or use drawBehind)
                this.drawContent()
                //You can change the scale if you want
                scale(scale = 1f) {
                    drawPath(
                        path = Path().apply {
                            reset()
                            //Draw the line
                            lineTo(size.width, size.height)
                        },
                        //The color of the line
                        color = Color.Black,
                        //2dp of thickness
                        style = Stroke(width = 2.dp.toPx())
                    )
                }
            }
            // If you want to add some padding (the line will go to the padding)
            .padding(start = 0.dp, top = 0.dp, end = 0.dp, bottom = 0.dp)
    ) {
        content()
    }
}
🤘 1
🔥 1