taasonei
taasonei

Reputation: 83

Get text after visual transformation

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

Upvotes: 1

Views: 576

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363935

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

Upvotes: 1

Related Questions