Hello, does someone has an Idea about how to count...
# compose
e
Hello, does someone has an Idea about how to count lines of a string in order to show or not see more button using compose like on the following screenshot ?
Sometimes the number of lines depends on the width of the screen or the orientation (landscape or portrait)
a
you can just set a lineCount value on the text and track the state internally ! essentially create a custom text composable that has a state that tracks whether the button is shown or not and then toggle it. https://github.com/abhishekdewan101/Scout/blob/782c088bbd79eab3581560020a9d4b3ccdf7f068/app/src/main/java/com/abhishek101/gamescout/features/main/details/GameDetailScreen.kt#L311 Heres and example
r
@Eric Ampire [MOD] u can get line count using
onTextLayout
in
Text
Copy code
val lines = remember { mutableStateOf(0)}
Text(onTextLayout = {                               
                 lines.value = it.lineCount
               },text="lsadfjalsd")
e
Thanks very much, Iet me tried