commandiron
commandiron

Reputation: 1473

How to use visual transformation on Text in Jetpack compose?

I need to implement visual transformation in Text but somehow Text doesn't have this parameter only TextFiled does have this parameter. How to find solution about this?

Example;

TextField(
    visualTransformation = // have this parameter
)

Text(
    visualTransformation = // doesnt have this parameter
)

I need that because i have to show big decimal contains comma and dot seperator and i have visual transformation of this.

Upvotes: 6

Views: 2559

Answers (1)

Dan Artillaga
Dan Artillaga

Reputation: 1945

You can use your custom VisualTransformation class to transform your text before passing it to Text.

val visualTransformation = remember { CustomVisualTransformation() }
val transformedText = remember(value) {
    visualTransformation.filter(AnnotatedString(value))
}.text

Text(text = transformedText)

Upvotes: 11

Related Questions