How to round only bottom 2 corners with drawRoundRect in Jetpack Compose Canvas

Viewed 1286

As the title says, I am just trying to figure out how can I round only the bottom 2 corners of the round rect.

drawScope.drawRoundRect(
                topLeft = Offset(0f,0f),
                size = Size(100f,100f),
                cornerRadius = CornerRadius(x = 10f, y = 10f),
                color = boxPaint.color
            )

This is my current code, which rounds all corners.

1 Answers

Seems like with drawRoundRect you only can setup left or right corner radius.

When you find that the Canvas API is missing something, you can draw almost anything using Path - it has much more flexible API.

val cornerRadius = CornerRadius(10f, 10f)
val path = Path().apply {
    addRoundRect(
        RoundRect(
            rect = Rect(
                offset = Offset(0f, 0f),
                size = Size(100f, 100f),
            ),
            bottomLeft = cornerRadius,
            bottomRight = cornerRadius,
        )
    )
}
drawPath(path, color = Color.Red)
Related