TextFieldValue
@Immutable class TextFieldValue
kotlin.Any | |
↳ | androidx.compose.ui.text.input.TextFieldValue |
A class holding information about the editing state.
The input service updates text selection, cursor, text and text composition. This class represents those values and it is possible to observe changes to those values in the text editing composables.
This class stores a snapshot of the input state of the edit buffer and provide utility functions for answering IME requests such as getTextBeforeCursor, getSelectedText.
Summary
Public constructors | |
---|---|
Public methods | |
---|---|
TextFieldValue |
Returns a copy of TextFieldValue in which composition is set to null. |
TextFieldValue |
Returns a copy of the TextField. |
Boolean | |
Int |
hashCode() |
String |
toString() |
Extension functions | ||||||
---|---|---|---|---|---|---|
From androidx.compose.ui.text.input
|
Properties | |
---|---|
TextRange? |
Composition range created by IME. |
TextRange |
The selection range. |
String |
the text to be rendered. |
Companion properties | |
---|---|
Saver<TextFieldValue, Any> |
The default Saver implementation for TextFieldValue. |
Public constructors
<init>
TextFieldValue(
text: String = "",
selection: TextRange = TextRange.Zero)
Parameters | |
---|---|
text: String = "" | the text to be rendered. |
selection: TextRange = TextRange.Zero | the selection range. If the selection is collapsed, it represents cursor location. When selection range is out of bounds, it is constrained with the text length. |
Public methods
commitComposition
fun commitComposition(): TextFieldValue
Returns a copy of TextFieldValue in which composition is set to null. When a TextFieldValue with null composition is passed to a TextField, if there was an active composition on the text, the changes will be committed.
See Also
copy
fun copy(
text: String = this.text,
selection: TextRange = this.selection
): TextFieldValue
Returns a copy of the TextField.
hashCode
fun hashCode(): Int
toString
fun toString(): String
Properties
composition
val composition: TextRange?
Composition range created by IME. If null, there is no composition range.
Composition can be set on the by the system, however it is possible to commit an existing composition using commitComposition.
Input service composition is an instance of text produced by IME. An example visual for the composition is that the currently composed word is visually separated from others with underline, or text background. For description of composition please check W3C IME Composition
selection
val selection: TextRange
The selection range. If the selection is collapsed, it represents cursor location. When selection range is out of bounds, it is constrained with the text length.