[KongchangAI]
Concept

TextFieldState

A new API in Jetpack Compose for managing text input state. It provides synchronous updates, edit sessions, selection ranges, undo/redo and other capabilities, and is built on the snapshot system for efficient UI updates.

Timeline (last 90 days)

Oct 30

TextFieldState is the text input solution stably provided since Compose 1.7; it updates synchronously as the user types without waiting for an asynchronous round trip, meeting the IME's synchronous requirements.

Unverified50%
Oct 30

In addition to the read-only text property, TextFieldState also encapsulates the active editing session, selection range, undo/redo state, and the span styles and paragraph styles used for formatting text.

Unverified50%
Oct 30

TextFieldState's internal properties are backed by the Compose snapshot system; when a composable reads the state during composition, layout, or drawing, it automatically subscribes to updates, thereby triggering only the necessary recomposition, layout, or drawing.

Unverified50%
Oct 30

The new API introduces InputTransformation, which intercepts user input before it reaches TextFieldState and provides the same API as TextFieldBuffer, including change list capability.

Unverified50%
Oct 30

A TextFieldState reference never changes after creation; user input changes its internal properties (such as the text field), so a StateFlow cannot perceive changes to its internal text, and StateFlow cannot be relied upon to observe the text.

Unverified50%
Oct 30

When hoisting TextFieldState to a ViewModel, it should be a direct property of the ViewModel rather than being placed in the UI state of an immutable data class, otherwise the copy method will create a new instance and cause loss of selection, cursor, and history.

Unverified50%
Oct 30

A ViewModel has no rememberSaveable, so a Saver must be configured manually for TextFieldState to restore state after process death.

Unverified50%
Oct 30

In a composable, rememberTextFieldState can be called to create a local TextFieldState, and it also helps with state restoration after process death.

Unverified50%

All Facts (8)

Unverified

TextFieldState is the text input solution stably provided since Compose 1.7; it updates synchronously as the user types without waiting for an asynchronous round trip, meeting the IME's synchronous requirements.

50%
Unverified

In addition to the read-only text property, TextFieldState also encapsulates the active editing session, selection range, undo/redo state, and the span styles and paragraph styles used for formatting text.

50%
Unverified

TextFieldState's internal properties are backed by the Compose snapshot system; when a composable reads the state during composition, layout, or drawing, it automatically subscribes to updates, thereby triggering only the necessary recomposition, layout, or drawing.

50%
Unverified

The new API introduces InputTransformation, which intercepts user input before it reaches TextFieldState and provides the same API as TextFieldBuffer, including change list capability.

50%
Unverified

A TextFieldState reference never changes after creation; user input changes its internal properties (such as the text field), so a StateFlow cannot perceive changes to its internal text, and StateFlow cannot be relied upon to observe the text.

50%
Unverified

When hoisting TextFieldState to a ViewModel, it should be a direct property of the ViewModel rather than being placed in the UI state of an immutable data class, otherwise the copy method will create a new instance and cause loss of selection, cursor, and history.

50%
Unverified

A ViewModel has no rememberSaveable, so a Saver must be configured manually for TextFieldState to restore state after process death.

50%
Unverified

In a composable, rememberTextFieldState can be called to create a local TextFieldState, and it also helps with state restoration after process death.

50%

Source Articles