ReadMoreText

fun ReadMoreText(text: String, expanded: Boolean, modifier: Modifier = Modifier, onExpandedChange: (Boolean) -> Unit? = null, contentPadding: PaddingValues = PaddingValues(0.dp), color: Color = Color.Unspecified, fontSize: TextUnit = TextUnit.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, textAlign: TextAlign = TextAlign.Unspecified, lineHeight: TextUnit = TextUnit.Unspecified, softWrap: Boolean = true, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current, readMoreText: String = "", readMoreColor: Color = Color.Unspecified, readMoreFontSize: TextUnit = TextUnit.Unspecified, readMoreFontStyle: FontStyle? = null, readMoreFontWeight: FontWeight? = null, readMoreFontFamily: FontFamily? = null, readMoreTextDecoration: TextDecoration? = null, readMoreMaxLines: Int = 2, readMoreOverflow: ReadMoreTextOverflow = ReadMoreTextOverflow.Ellipsis, readMoreStyle: SpanStyle = style.toSpanStyle(), readLessText: String = "", readLessColor: Color = readMoreColor, readLessFontSize: TextUnit = readMoreFontSize, readLessFontStyle: FontStyle? = readMoreFontStyle, readLessFontWeight: FontWeight? = readMoreFontWeight, readLessFontFamily: FontFamily? = readMoreFontFamily, readLessTextDecoration: TextDecoration? = readMoreTextDecoration, readLessStyle: SpanStyle = readMoreStyle, toggleArea: ToggleArea = ToggleArea.All)
fun ReadMoreText(text: AnnotatedString, expanded: Boolean, modifier: Modifier = Modifier, onExpandedChange: (Boolean) -> Unit? = null, contentPadding: PaddingValues = PaddingValues(0.dp), color: Color = Color.Unspecified, fontSize: TextUnit = TextUnit.Unspecified, fontStyle: FontStyle? = null, fontWeight: FontWeight? = null, fontFamily: FontFamily? = null, letterSpacing: TextUnit = TextUnit.Unspecified, textDecoration: TextDecoration? = null, textAlign: TextAlign = TextAlign.Unspecified, lineHeight: TextUnit = TextUnit.Unspecified, softWrap: Boolean = true, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current, readMoreText: String = "", readMoreColor: Color = Color.Unspecified, readMoreFontSize: TextUnit = TextUnit.Unspecified, readMoreFontStyle: FontStyle? = null, readMoreFontWeight: FontWeight? = null, readMoreFontFamily: FontFamily? = null, readMoreTextDecoration: TextDecoration? = null, readMoreMaxLines: Int = 2, readMoreOverflow: ReadMoreTextOverflow = ReadMoreTextOverflow.Ellipsis, readMoreStyle: SpanStyle = style.toSpanStyle(), readLessText: String = "", readLessColor: Color = readMoreColor, readLessFontSize: TextUnit = readMoreFontSize, readLessFontStyle: FontStyle? = readMoreFontStyle, readLessFontWeight: FontWeight? = readMoreFontWeight, readLessFontFamily: FontFamily? = readMoreFontFamily, readLessTextDecoration: TextDecoration? = readMoreTextDecoration, readLessStyle: SpanStyle = readMoreStyle, toggleArea: ToggleArea = ToggleArea.All)

High level element that displays text with read more.

The default style uses the LocalTextStyle provided by the MaterialTheme / components. If you are setting your own style, you may want to consider first retrieving LocalTextStyle, and using TextStyle.copy to keep any theme defined attributes, only modifying the specific attributes you want to override.

For ease of use, commonly used parameters from TextStyle are also present here. The order of precedence is as follows:

  • If a parameter is explicitly set here (i.e, it is not null or TextUnit.Unspecified), then this parameter will always be used.

  • If a parameter is not set, (null or TextUnit.Unspecified), then the corresponding value from style will be used instead.

Additionally, for color, if color is not set, and style does not have a color, then LocalContentColor will be used with an alpha of LocalContentAlpha- this allows this Text or element containing this Text to adapt to different background colors and still maintain contrast and accessibility.

Parameters

text

The text to be displayed.

expanded

whether this text is expanded or collapsed.

modifier

Modifier to apply to this layout node.

onExpandedChange

called when this text is clicked. If null, then this text will not be interactable, unless something else handles its input events and updates its state.

contentPadding

a padding around the text.

color

Color to apply to the text. If Color.Unspecified, and style has no color set, this will be LocalContentColor.

fontSize

The size of glyphs to use when painting the text. See TextStyle.fontSize.

fontStyle

The typeface variant to use when drawing the letters (e.g., italic). See TextStyle.fontStyle.

fontWeight

The typeface thickness to use when painting the text (e.g., FontWeight.Bold).

fontFamily

The font family to be used when rendering the text. See TextStyle.fontFamily.

letterSpacing

The amount of space to add between each letter. See TextStyle.letterSpacing.

textDecoration

The decorations to paint on the text (e.g., an underline). See TextStyle.textDecoration.

textAlign

The alignment of the text within the lines of the paragraph. See TextStyle.textAlign.

lineHeight

Line height for the Paragraph in TextUnit unit, e.g. SP or EM. See TextStyle.lineHeight.

softWrap

Whether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space. If softWrap is false, readMoreOverflow and TextAlign may have unexpected effects.

onTextLayout

Callback that is executed when a new text layout is calculated. A TextLayoutResult object that callback provides contains paragraph information, size of the text, baselines and other details. The callback can be used to add additional decoration or functionality to the text. For example, to draw selection around the text.

style

Style configuration for the text such as color, font, line height etc.

readMoreText

The read more text to be displayed in the collapsed state.

readMoreColor

Color to apply to the read more text. If Color.Unspecified, and style has no color set, this will be LocalContentColor.

readMoreFontSize

The size of glyphs to use when painting the read more text. See TextStyle.fontSize.

readMoreFontStyle

The typeface variant to use when drawing the read more letters (e.g., italic). See TextStyle.fontStyle.

readMoreFontWeight

The typeface thickness to use when painting the read more text (e.g., FontWeight.Bold).

readMoreFontFamily

The font family to be used when rendering the read more text. See TextStyle.fontFamily.

readMoreTextDecoration

The decorations to paint on the read more text (e.g., an underline). See TextStyle.textDecoration.

readMoreMaxLines

An optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to readMoreOverflow. If it is not null, then it must be greater than zero.

readMoreOverflow

How visual overflow should be handled in the collapsed state.

readMoreStyle

Style configuration for the read more text such as color, font, line height etc.

readLessText

The read less text to be displayed in the expanded state.

readLessColor

Color to apply to the read less text. If Color.Unspecified, and style has no color set, this will be LocalContentColor.

readLessFontSize

The size of glyphs to use when painting the read less text. See TextStyle.fontSize.

readLessFontStyle

The typeface variant to use when drawing the read less letters (e.g., italic). See TextStyle.fontStyle.

readLessFontWeight

The typeface thickness to use when painting the read less text (e.g., FontWeight.Bold).

readLessFontFamily

The font family to be used when rendering the read less text. See TextStyle.fontFamily.

readLessTextDecoration

The decorations to paint on the read less text (e.g., an underline). See TextStyle.textDecoration.

readLessStyle

Style configuration for the read less text such as color, font, line height etc.

toggleArea

A clickable area of text to toggle.