Function

forEachChange

Iterates over all changes in this ChangeList in order of their appearance in the text (from the lowest character offset to the highest).

BasicTextFieldChangeIterationSample

@Sampled
@Composable
fun BasicTextFieldChangeIterationSample() {
    // Print a log message every time the text is changed.
    BasicTextField(
        state = rememberTextFieldState(),
        inputTransformation = {
            changes.forEachChange { sourceRange, replacedLength ->
                val newString = asCharSequence().substring(sourceRange)
                println("""$replacedLength characters were replaced with "$newString"""")
            }
        },
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: