1

Is there any way to get text after applying visualTransformtaion from text field in Compose? onTextChange and onValueChange return the input before visual transformations

I checked the docs and found inside CoreTextField that this transformation is setting into state by TextFieldState and TextDelegate. But I couldn't see any callbacks to get this changes back

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
taasonei
  • 53
  • 5

1 Answers1

1

You have to apply the same filter used by the VisualTransformation

    var text by remember { mutableStateOf("") }
    val visualTransformation = MyVisualTransformation()

    TextField(
        value = text,
        onValueChange = { text = it },
        visualTransformation = visualTransformation

    )

    val transformedText = remember(text, visualTransformation) {
        visualTransformation.filter(AnnotatedString(text))
    }.text.text
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841