I’m trying to get text to enter a currency-specifi...
# compose
c
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
"obviously" not. Arabic writes decimals left-to-right even when the surrounding context is right-to-left
❤️ 1
c
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
there's no reversing going on there, you're still writing number in big-endian order
c
That’s right. I wasn’t talking about endianness.
e
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
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
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
Yes
Are you suggesting it’s simply a VisualTransformation I need? Because the numbers will still be incorrect.
e
how will they be incorrect? as long as the cursor is at the end, the next number will go to the right place
c
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
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
right, there's Java's
NumberFormat.getCurrencyInstance()
although building a VisualTransform around that would still take some work to get the OffsetMapping right
👍 1