I want the compose Text’s parent (Row -> Box) to wrap its content (in this case, the Text itself) to maintain minimal padding. In the current code, long words are soft-wrapped, but there’s excessive space between the text and the right edge of the Row. I’d like to dynamically adjust the padding to the minimum possible value while keeping the number of lines in the container (Row/Box) to a minimum.
@Composable
fun ChatMessageExample() {
Box(
modifier = Modifier
.padding(16.dp)
.clip(RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp, bottomStart = 18.dp, bottomEnd = 0.dp))
.background(color = Color.LightGray)
) {
Row(
modifier = Modifier
.padding(top = 12.dp, bottom = 12.dp, start = 16.dp, end = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.padding(end = 4.dp),
text = "I want to make sure the width is correctlyAdjusted with text.",
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Normal,
lineHeight = 26.sp),
overflow = TextOverflow.Clip,
softWrap = true
)
}
}
}