chanjungskim
03/28/2023, 9:16 AMButton(
onClick = {
paymentType = OrderData.PaymentType.NICEPAY
},
shape = RoundedCornerShape(0.dp),
contentPadding = PaddingValues(0.dp),
interactionSource = NoRippleInteractionSource(),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Red001,
contentColor = Color.Green001
),
modifier = Modifier
.weight(0.5f)
.height(tabHeight)
.drawToggleBorder(
isSelected = paymentType == OrderData.PaymentType.NICEPAY,
strokeWidth = 1.dp
)
) {
Text(
text = "Hello World",
fontSize = fontSize,
color = Color.Black
)
}
fun Modifier.drawToggleBorder(
isSelected: Boolean,
strokeWidth: Dp,
defaultBorderColor: androidx.compose.ui.graphics.Color = Color.Gray01,
borderColor: androidx.compose.ui.graphics.Color = Color.Black
) = composed(
factory = {
val density = LocalDensity.current
val strokeWidthPx = density.run { strokeWidth.toPx() }
Modifier.drawBehind {
val width = size.width
val height = size.height
if (isSelected) {
drawRect(
color = Color.White
)
drawLine(
color = borderColor,
start = Offset(x = 0f, y = 0f),
end = Offset(x = 0f, y = height),
strokeWidth = strokeWidthPx
)
drawLine(
color = borderColor,
start = Offset(x = 0f, y = 0f),
end = Offset(x = width, y = 0f),
strokeWidth = strokeWidthPx
)
drawLine(
color = borderColor,
start = Offset(x = width, y = 0f),
end = Offset(x = width, y = height),
strokeWidth = strokeWidthPx
)
} else {
drawRect(
color = Gray016
)
drawLine(
color = borderColor,
start = Offset(x = 0f, y = height),
end = Offset(x = width, y = height),
strokeWidth = strokeWidthPx
)
drawLine(
color = defaultBorderColor,
start = Offset(x = 0f, y = 0f),
end = Offset(x = 0f, y = height),
strokeWidth = strokeWidthPx
)
drawLine(
color = defaultBorderColor,
start = Offset(x = width, y = 0f),
end = Offset(x = width, y = height),
strokeWidth = strokeWidthPx
)
}
}
}
)