Function

byValue

Creates an InputTransformation from a function that accepts both the current and proposed TextFieldCharSequence and returns the TextFieldCharSequence to use for the field.

BasicTextFieldInputTransformationByValueChooseSample

@Sampled
@Composable
fun BasicTextFieldInputTransformationByValueChooseSample() {
    val state = remember { TextFieldState() }
    BasicTextField(
        state,
        // Reject whitespace.
        inputTransformation =
            InputTransformation.byValue { current, proposed ->
                if ("""\s""".toRegex() in proposed) current else proposed
            },
    )
}

BasicTextFieldInputTransformationByValueReplaceSample

@Sampled
@Composable
fun BasicTextFieldInputTransformationByValueReplaceSample() {
    val state = remember { TextFieldState() }
    BasicTextField(
        state,
        // Convert tabs to spaces.
        inputTransformation =
            InputTransformation.byValue { _, proposed ->
                proposed.replace("""\t""".toRegex(), "  ")
            },
    )
}
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: