Saturday, 18 February 2023

Clipping to this shape makes all the size modifiers ineffective

I have a simple Box Composable which I wanna clip to a custom shape, but whenever I try it, the shape's size remains pretty rigid and small. I've tried scaling on the path level using Matrix(), but to no avail. Here's the sample -

const val clockHand = "M0 80.52L2 86l2-5.48V2.74C4 1.83 3.6 0 2 0S0 1.83 0 2.74v77.78Z"
val clockHandShape = object : Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density
    ): Outline {
        return Outline.Generic(PathParser.createPathFromPathData(clockHand).asComposePath())
    }
}

Box(
                        modifier = Modifier
                            .background(Color.Green)
                            .clip(clockHandShape)
                            .width(30.dp)
                            .height(50.dp)
                            .background(Color(0xFFFF007A))
                            .layoutId("hourHand")
) {}

As a control, you can replace the custom shape with a pre-defined one like RectangleShape or CircleShape etc.



from Clipping to this shape makes all the size modifiers ineffective

No comments:

Post a Comment