Is there not a good way in compose to show a Text ...
# compose
a
Is there not a good way in compose to show a Text component which automatically ellipses whenever there is a visible overflow.?? If not, can you give me any solution to achieve that. My Text component with weight 1 is actually not clipping properly.
c
Got code to show? I've had this working correctly in the past.
a
Sorry, I thought no one replied.
Here is an example I extracted.
Copy code
@Preview
@Composable
fun Xyz(){
    Column(
        verticalArrangement = Arrangement.Center,
        modifier = Modifier.size(width = 260.dp, height = 73.dp).background(Color.White).padding(16.dp)
    ) {
        UiText(
            text = "Some very very very very very very very very very very very long text here.",
            overflow = TextOverflow.Ellipsis,
            modifier = Modifier
                .fillMaxWidth()
                .weight(1F, fill = false),
        )

        UiText(
            text = "Some other text here.",
            emphasis = TextEmphasis.Medium,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
                .padding(top = 4.dp)
        )
    }
}
This is the result @Colton Idle
If I go just one dp less in height then it works fine. But at runtime we can't really use it if its not reliable.
c
@Siyamed?
a
@Siyamed?? Help Siyamed help 😄
s
Sorry 😕
I think you are asking about this: https://issuetracker.google.com/issues/168720622
in this exampe you know the max height it looks like you want to keep the second text, but want to ellipsize the first text?
in the current system you can provide a maxLines and then ellipsize will work for the first one.
otherwise you can get the TextLayout result from each text, and set the height of the first one based on the height of those two texts inside the column.