I have very specific divider which should overlap nearby items with rounded corners:

But this divider should overlap nearby items of recyclerView like this:

I've created the custom layout for this divider and this is how it looks:
@Composable
fun Divider() {
Box(
modifier = Modifier
.height(6.dp)
.fillMaxWidth()
.zIndex(1f)
) {
CustomLayout(verticalOffset = 64.dp) {
DividerWithCorners()
}
}
}
@Composable
private fun DividerWithCorners() {
Column(modifier = Modifier) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Corner(modifier = Modifier.rotate(-90f))
Corner(modifier = Modifier.rotate(180f))
}
Spacer(
modifier = Modifier
.height(6.dp)
.fillMaxWidth()
.background(Color.Black)
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Corner(modifier = Modifier.rotate(0f))
Corner(modifier = Modifier.rotate(90f))
}
}
}
@Composable
private fun CustomLayout(verticalOffset: Dp, content: @Composable () -> Unit) {
Layout(
modifier = Modifier
.fillMaxWidth()
.height(70.dp),
content = content
) { measurables, constraints ->
val placaebles = measurables.map { measurable ->
val looseConstraints = constraints.copy(
minWidth = 0,
minHeight = 0,
)
measurable.measure(
constraints = looseConstraints.offset(
vertical = verticalOffset.roundToPx(),
)
)
}
layout(
placaebles.maxOf { it.width },
placaebles.sumOf { it.height }
) {
placaebles.forEach { placeable ->
placeable.place(0, 0)
}
}
}
}
@Composable
private fun Corner(modifier: Modifier = Modifier) {
val size = 32.dp
val bgColor = Color.Black
Canvas(modifier = modifier.size(size)) {
drawPath(
path = Path().apply {
lineTo(size.toPx(), 0f)
arcTo(
rect = Rect(
left = 0f,
top = 0f,
right = 2 * size.toPx(),
bottom = 2 * size.toPx()
),
startAngleDegrees = 270f,
sweepAngleDegrees = -90f,
forceMoveTo = false
)
lineTo(0f, size.toPx())
close()
}, color = bgColor
)
}
}
This is not an issue with using LazyColumn as you see. But I need to put this item inside RecyclerView (I use groupie delegate adapter). And this is the result of my attempts with xml RecyclerView:
Looks like this corners just not rendering because they are out of bounds of compose view. Or maybe it is some compose magic with optimisation idk.
I've spend a life trying to solve this issue. Please help me to figure out is it possible and if it is, how should I modify my code.
