https://kotlinlang.org logo
#compose
Title
# compose
c

colintheshots

04/15/2022, 9:20 PM
I’m trying to get text to enter a currency-specific textfield from right to left with two decimal places and a locale-dependent DecimalFormatSymbol. Essentially, this is what Paypal/Venmo and others do and it’s become a pattern many people are familiar with. Obviously, I’ll need to swap the order for RTL languages. I’ve got the formatting working, but the text still enters from left to right. Does anyone have any tips to change the order the text is entered? Has anyone built a UI element like this in Compose already?
e

ephemient

04/15/2022, 9:22 PM
"obviously" not. Arabic writes decimals left-to-right even when the surrounding context is right-to-left
❤️ 1
c

colintheshots

04/15/2022, 9:23 PM
Yes, I’m looking to reverse the normal ordering in both LTR and RTL.
It looks like “0.00” -> “0.01" -> “0.10” etc.
e

ephemient

04/15/2022, 9:24 PM
there's no reversing going on there, you're still writing number in big-endian order
c

colintheshots

04/15/2022, 9:24 PM
That’s right. I wasn’t talking about endianness.
e

ephemient

04/15/2022, 9:25 PM
I just want to make it clear that "I’ll need to swap the order for RTL languages" is not what you should do. numbers are naturally input in exactly the same order and display the same way
c

colintheshots

04/15/2022, 9:26 PM
I’m confused by the language you’re using. I AM reversing the normal ordering of entering the number. The numbers entered start from the right and slide to the left as more is written.
e

ephemient

04/15/2022, 9:26 PM
if you didn't format anything, you'd still be entering numbers in the same order
e.g. the key presses
1
2
3
normally result in
123
, and you want it to appear as
1.23
, not
3.21
c

colintheshots

04/15/2022, 9:28 PM
Yes
Are you suggesting it’s simply a VisualTransformation I need? Because the numbers will still be incorrect.
e

ephemient

04/15/2022, 9:30 PM
how will they be incorrect? as long as the cursor is at the end, the next number will go to the right place
c

colintheshots

04/15/2022, 9:33 PM
But the cursor isn’t always at the end. In fact, I often need to pre-populate the form in many cases and let the user edit the number in the middle. I’m simply starting from the right when the value starts with “0.00”.
I guess I can treat the input as an integer and do a visual transformation. Then add the decimal when reading/saving the value later.
Thanks, I’ll give it a try using this method!
s

Siyamed

04/16/2022, 5:48 AM
Some scripts have numbers that are RTL (https://en.wikipedia.org/wiki/Adlam_script#Digits)
in general if a system Formatter can give you the result use that one.
e

ephemient

04/17/2022, 12:02 AM
right, there's Java's
NumberFormat.getCurrencyInstance()
although building a VisualTransform around that would still take some work to get the OffsetMapping right
👍 1
11 Views