Thomas Dougherty
08/30/2023, 10:56 PMThomas Dougherty
08/30/2023, 10:57 PMThomas Dougherty
08/30/2023, 10:58 PM@Composable
fun Pin() {
Column(modifier = Modifier.fillMaxSize()) {
val pinShape = PinShape(
cornerRadiusInDp = 8.dp,
tipHeight = 8.dp,
tipWidth = 16.dp
)
Row(
modifier = Modifier
.background(
color = Color.Blue, shape = RoundedCornerShape(3.dp)
)
.clip(shape = RoundedCornerShape(3.dp))
.padding(8.dp)
) {
Icon(
imageVector = Icons.Rounded.Face, contentDescription = "face",
modifier = Modifier.size(24.dp), tint = Color.White
)
Spacer(modifier = Modifier.width(8.dp))
Text(text = "1328", fontSize = 16.sp, color = Color.White)
}
Row(
modifier = Modifier
.background(
color = Color.Blue, shape = pinShape
)
.clip(pinShape)
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Rounded.Face, contentDescription = "face",
modifier = Modifier.size(24.dp), tint = Color.White
)
Spacer(modifier = Modifier.width(8.dp))
Text(text = "1328", fontSize = 16.sp, color = Color.White)
}
}
}
Thomas Dougherty
08/30/2023, 10:58 PMThomas Dougherty
08/30/2023, 10:59 PMclass PinShape(private val cornerRadiusInDp: Dp, val tipHeight: Dp, val tipWidth: Dp) : Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density
): Outline {
val thInPx = tipHeight.value * density.density
val twInPx = tipWidth.value * density.density
val cornerRadius = cornerRadiusInDp.value * density.density
return Outline.Generic(
Path().apply {
addRoundRect(RoundRect(
top = 0f + thInPx,
bottom = size.height - thInPx,
left = 0f,
right = size.width,
cornerRadius = CornerRadius(cornerRadius)))
moveTo((size.width / 2f) + (twInPx / 2f), size.height - thInPx)
lineTo((size.width / 2f), size.height)
lineTo((size.width / 2f) - (twInPx / 2f), size.height - thInPx)
}
)
}
}
Thomas Dougherty
08/30/2023, 11:01 PMThomas Dougherty
08/30/2023, 11:02 PMThomas Dougherty
08/30/2023, 11:02 PMmodifier = Modifier
.background(
color = Color.Blue, shape = pinShape
)
.clip(pinShape)
.border(width = 2.dp, color = Color.Red, shape = pinShape)
.padding(8.dp),
Thomas Dougherty
08/30/2023, 11:03 PMromainguy
08/30/2023, 11:06 PMromainguy
08/30/2023, 11:06 PMromainguy
08/30/2023, 11:07 PMromainguy
08/30/2023, 11:07 PMThomas Dougherty
08/30/2023, 11:09 PMKirill Grouchnikov
08/30/2023, 11:12 PMThomas Dougherty
08/30/2023, 11:14 PMKirill Grouchnikov
08/30/2023, 11:14 PMThomas Dougherty
08/30/2023, 11:19 PMThomas Dougherty
08/30/2023, 11:19 PMRow(
modifier = Modifier
.background(
color = Color.Blue, shape = pinShape
)
.clip(pinShape)
.padding(top = 16.dp, bottom = 16.dp, start = 8.dp, end = 8.dp),
verticalAlignment = Alignment.CenterVertically
)
Kirill Grouchnikov
08/30/2023, 11:20 PMThomas Dougherty
08/30/2023, 11:21 PMKirill Grouchnikov
08/30/2023, 11:22 PMThomas Dougherty
08/31/2023, 12:39 AMclass PinShape(private val cornerRadiusInDp: Dp, val tipHeight: Dp, val tipWidth: Dp) : Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density
): Outline {
val thInPx = tipHeight.value * density.density
val twInPx = tipWidth.value * density.density
val cornerRadius = cornerRadiusInDp.value * density.density
val rectangle = Path().apply {
addRoundRect(RoundRect(
top = 0f + thInPx,
bottom = size.height - thInPx,
left = 0f,
right = size.width,
cornerRadius = CornerRadius(cornerRadius)))
}
val point = Path().apply {
moveTo((size.width / 2f) + (twInPx / 2f), size.height - thInPx)
lineTo((size.width / 2f), size.height)
lineTo((size.width / 2f) - (twInPx / 2f), size.height - thInPx)
}
return Outline.Generic(
Path.combine(PathOperation.Union, rectangle, point)
)
}
}
Ended up doing the combine of the paths in the shape and the border works! Thanks @romainguy & @Kirill Grouchnikov