AutoSizeText

fun AutoSizeText(text: String, modifier: Modifier = Modifier, suggestedFontSizes: ImmutableWrapper<List<TextUnit>> = emptyList<TextUnit>().toImmutableWrapper(), minTextSize: TextUnit = TextUnit.Unspecified, maxTextSize: TextUnit = TextUnit.Unspecified, stepGranularityTextSize: TextUnit = TextUnit.Unspecified, textAlignment: Alignment = Alignment.Center, color: Color = Color.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, textAlign: TextAlign? = null, lineHeight: TextUnit = TextUnit.Unspecified, softWrap: Boolean = true, maxLines: Int = 1, minLines: Int = 1, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current)

Composable function that automatically adjusts the size of text to fit within the given constraints.

Features:

  1. Best performance: Utilizes a dichotomous binary search algorithm to quickly find the optimal text size without unnecessary iterations.

  2. Text alignment support: Supports 6 possible alignment values through the Alignment interface.

  3. Material Design 3 support.

  4. Font scaling support: Changing the font scale by the user does not affect the visual rendering result.

Limitation:

  1. Does not work well when maxLine is greater than 1.

  2. Does not work well when changing lineHeight

Author

Reda El Madini - For support, contact gladiatorkilo@gmail.com

Parameters

text

The text to be displayed.

modifier

The modifier for the text composable.

suggestedFontSizes

The suggested font sizes to choose from.

minTextSize

The minimum text size allowed.

maxTextSize

The maximum text size allowed.

stepGranularityTextSize

The step size for adjusting the text size.

textAlignment

The alignment of the text within its container.

color

The color of the text.

fontStyle

The font style of the text.

fontWeight

The font weight of the text.

fontFamily

The font family of the text.

letterSpacing

The letter spacing of the text.

textDecoration

The text decoration style.

textAlign

The alignment of the text within the lines of the paragraph.

lineHeight

The line height of the text.

softWrap

Whether the text should break at soft line breaks.

maxLines

The maximum number of lines for the text.

minLines

The minimum number of lines for the text.

onTextLayout

Callback invoked when the text layout is available.

style

The base style to apply to the text.


fun AutoSizeText(text: AnnotatedString, modifier: Modifier = Modifier, suggestedFontSizes: ImmutableWrapper<List<TextUnit>> = emptyList<TextUnit>().toImmutableWrapper(), minTextSize: TextUnit = TextUnit.Unspecified, maxTextSize: TextUnit = TextUnit.Unspecified, stepGranularityTextSize: TextUnit = TextUnit.Unspecified, textAlignment: Alignment = Alignment.Center, color: Color = Color.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, textAlign: TextAlign? = null, lineHeight: TextUnit = TextUnit.Unspecified, softWrap: Boolean = true, maxLines: Int = 1, minLines: Int = 1, inlineContent: ImmutableWrapper<Map<String, InlineTextContent>> = mapOf<String, InlineTextContent>().toImmutableWrapper(), onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current)