Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading