Skip to content

Instantly share code, notes, and snippets.

@Abhimanyu14
Created June 27, 2023 17:34
Show Gist options
  • Save Abhimanyu14/6f09328c721e045b2e4af27bc61245bc to your computer and use it in GitHub Desktop.
Save Abhimanyu14/6f09328c721e045b2e4af27bc61245bc to your computer and use it in GitHub Desktop.
@Composable
fun ScrollingTextWithMaxLinesDemo() {
val textMeasurer = rememberTextMeasurer()
val density = LocalDensity.current
val textHeight = with(density) {
textMeasurer.measure(
text = randomText,
maxLines = 10,
style = TextStyle(),
).size.height.toDp()
}
Text(
text = randomText,
modifier = Modifier
.height(textHeight)
.verticalScroll(rememberScrollState())
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment