I am trying to create this shape using canvas enter image description here
I am trying to create this shape using canvas enter image description here
You can subclass Shape interface, and implement createOutline method. Outline.Generic accepts any Path object, so you can build any shape by adding lines, curves, rounded rects, etc.
class CustomShape(val param: Int): Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density,
) = Outline.Generic(Path().apply {
// build your path here depending on params and size
})
}
If the shape has no parameters, it can be defined as object instead of class.
Then you can pass this custom shape in any modifier which accepts Shape, like Modifier.background(color, shape = CustomShape(...)), border, or in views like Surface.