Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-02 18:10:53 +08:00
parent eee8285522
commit 81ad4db392
5 changed files with 109 additions and 73 deletions

View file

@ -20,6 +20,8 @@ fun ResizableText(
fontSizeRange: FontSizeRange,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
style: TextStyle = LocalTextStyle.current,
) {
val fontSizeValue = remember { mutableStateOf(fontSizeRange.max.value) }
@ -33,12 +35,13 @@ fun ResizableText(
}
Text(
modifier = modifier.drawWithContent { if (readyToDraw.value) drawContent() },
text = text,
modifier = modifier.drawWithContent { if (readyToDraw.value) drawContent() },
color = color,
softWrap = false,
style = style,
fontSize = fontSizeValue.value.sp,
overflow = overflow,
softWrap = false,
maxLines = maxLines,
onTextLayout = {
if (it.hasVisualOverflow) {
val nextFontSizeValue = fontSizeValue.value - fontSizeRange.step.value
@ -52,6 +55,7 @@ fun ResizableText(
readyToDraw.value = true
}
},
style = style,
)
}