Hello, hope this is the correct channel for this t...
# compose
j
Hello, hope this is the correct channel for this type of question. I'm stuck on an issue and I can't figure out if it's possible to achieve my expected result. I want the first text containing the name to be able to show on maxLines=2 and always wrap it's content making the second text always appear close to the name and always be shown in full. When the name is shown on 2 lines the text always occupies the full width, is it possible to have it wrap it's content when the name is shown on 2 lines? See example code in thread, in my example scenario for
Alexanderiaddd Montgomerysoe
I want the name text to wrap the content and not occupy the full width since it creates a space between the two text compostables , is this possible to achieve?
Copy code
@Composable
fun TestComposable(name: String) {
    Row(
        modifier = Modifier
            .background(Color.White)
            .wrapContentWidth()
            .padding(8.dp),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.Start,
    ) {
        Icon(
            imageVector = Icons.Default.Face,
            contentDescription = "PlaceholderIcon",
            modifier = Modifier.size(48.dp),
            tint = Color.Red,
        )
        Text(
            modifier = Modifier
                .padding(horizontal = 12.dp)
                .offset(y = (-2).dp)
                .widthIn(max = 190.dp)
                .background(Color.Green),
            text = name,
            style = Typography.bodyMedium,
            color = Color.Black,
            overflow = TextOverflow.Ellipsis,
            maxLines = 2,
            softWrap = true,
        )
        Text(
            modifier = Modifier
                .clip(CircleShape)
                .wrapContentWidth()
                .background(Color.Cyan)
                .padding(
                    start = 8.dp,
                    end = 8.dp,
                    top = 4.dp,
                    bottom = 6.dp,
                ),
            style = Typography.bodyMedium,
            text = "Not at the desk",
            color = Color.Black,
            maxLines = 1,
        )
    }
}

private class NamesPreviewProvider : PreviewParameterProvider<String> {
    override val values: Sequence<String> = listOf(
//        "Jo Lee",
//        "Ty Wu",
//        "Ana Kim",
//        "Scarlett Davis",
        "Benjamin Williams Something",
        "Alexanderiaddd Montgomerysoe",
        "Benjami bb Button aaa the third of something blabla",
    ).asSequence()
}

@Preview
@Composable
private fun TestComposablePreview(@PreviewParameter(NamesPreviewProvider::class) name: String) {
    TestComposable(name)
}
j
Looks like the same issue I'm having, thanks @Stylianos Gakis will try this workaround 🙏
And apologies for not search thoroughly enough before posting 😅
s
It's a special enough issue that I think it'd be quite hard to be able to know the words to use to search for it 😅 Don't blame you for asking again at all 😄
j
The workaround seems to do the trick, thank you so much! I've been going crazy trying to solve this issue.
2