← Back to Foundation
ClickableText
Component
in
Foundation
. Since 0.1.0-dev15Overview
Code Examples
A continent version of BasicText component to be able to handle click event on the text.
This is a shorthand of BasicText with pointerInput to be able to handle click event easily.
Overloads
ClickableText
@Composable
fun ClickableText(
text: AnnotatedString,
modifier: Modifier = Modifier,
style: TextStyle = TextStyle.Default,
softWrap: Boolean = true,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
onClick: (Int) -> Unit
)
Parameters
Name | Description |
---|---|
text | The text to be displayed. |
modifier | Modifier to apply to this layout node. |
style | Style configuration for the text such as color, font, line height etc. |
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, overflow and TextAlign may have unexpected effects. |
overflow | How visual overflow should be handled. |
maxLines | 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 overflow and softWrap. If it is not null, then it must be greater than zero. |
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. |
onClick | Callback that is executed when users click the text. This callback is called with clicked character's offset |
ClickableText
@ExperimentalFoundationApi // when removing this experimental annotation,
// onHover should be nullable with null as default. The other ClickableText
// should be deprecated as hidden and simply call this function.
@Composable
fun ClickableText(
text: AnnotatedString,
onHover: ((Int?) -> Unit),
modifier: Modifier = Modifier,
style: TextStyle = TextStyle.Default,
softWrap: Boolean = true,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
onClick: (Int) -> Unit
)
Parameters
Name | Description |
---|---|
text | The text to be displayed. |
modifier | Modifier to apply to this layout node. |
style | Style configuration for the text such as color, font, line height etc. |
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, overflow and TextAlign may have unexpected effects. |
overflow | How visual overflow should be handled. |
maxLines | 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 overflow and softWrap. If it is not null, then it must be greater than zero. |
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. |
onHover | Callback that is executed when user hovers over the text with a mouse or trackpad. This callback is called with the hovered character's offset or null if the cursor is no longer hovering this. |
onClick | Callback that is executed when users click the text. This callback is called with clicked character's offset. Note: API research for improvements on clickable text and related functionality is still ongoing so keeping this experimental to avoid future churn |