Daniel Candeias
07/03/2024, 3:38 PMZach Klippenstein (he/him) [MOD]
07/03/2024, 4:14 PMDaniel Candeias
07/03/2024, 4:15 PM@Preview
@Composable
fun MyComponent() {
val minLineWidth = 6.dp
val maxLineWidth = 16.dp
val idLeft = "line_left"
val idRight = "line_right"
val idText = "text"
val constraint = ConstraintSet {
val startLineRef = createRefFor(idLeft)
val endLineRef = createRefFor(idRight)
val textRef = createRefFor(idText)
constrain(startLineRef) {
start.linkTo(parent.start)
end.linkTo(textRef.start)
top.linkTo(<http://parent.top|parent.top>)
bottom.linkTo(parent.bottom)
width = Dimension.preferredWrapContent.atLeast(minLineWidth).atMost(maxLineWidth)
}
constrain(endLineRef) {
end.linkTo(parent.end)
start.linkTo(textRef.end)
top.linkTo(<http://parent.top|parent.top>)
bottom.linkTo(parent.bottom)
width = Dimension.preferredWrapContent.atLeast(minLineWidth).atMost(maxLineWidth)
}
constrain(textRef) {
start.linkTo(startLineRef.end)
end.linkTo(endLineRef.start)
width = Dimension.fillToConstraints.atMostWrapContent
}
}
ConstraintLayout(
modifier = Modifier.requiredWidth(80.dp),
constraintSet = constraint,
) {
Divider(
modifier = Modifier
.layoutId(idLeft),
color = Color.Red
)
Divider(
modifier = Modifier
.layoutId(idRight),
color = Color.Blue
)
Text(
modifier = Modifier
.layoutId(idText),
text = "ABCDEFGHIJKL",
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
Colton Idle
07/03/2024, 11:15 PMDaniel Candeias
07/04/2024, 11:27 AMZach Klippenstein (he/him) [MOD]
07/04/2024, 4:07 PMgildor
07/05/2024, 3:20 AM