I'm rendering a long text in a Text composable. I would like to detect the last displayed line and character.
This is the code I'm using:
Text(
longText,
overflow = TextOverflow.Clip,
onTextLayout = { textLayoutResult ->
val lastLineIndex = textLayoutResult.lineCount - 1
val lastCharacterIndex = textLayoutResult.getLineEnd(lastLineIndex, visibleEnd = true)
...
}
)
I have two problems with this code:
- The last line is displayed but cut in half, I would have expected this to be clipped altogether
- the lastLineIndex and lastCharacterIndex refer to the whole longText rendering, not just the portion that fits without overflow (e.g. lastLineIndex is 1000 instead of 14)
If I use TextOverflow.Ellipsis it works as I would expect (last line that was previously only half rendered is removed and the indices refer to the visible part of the text). However I don't want to have the ... at the end.
I thought Clip works like Ellipsis, just not showing the ... Is that understanding not correct?