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

Timon Bohn

03/01/2021, 5:57 PM
Hey folks! Any idea on how to properly auto format decimal numbers inside a TextField based on the locale? Right now we figured out a half working solution using number formatter. But the cursor does not stay at the end of the number and periodically moves one step further to the front.
d

Daniel

03/01/2021, 7:15 PM
Is the issue that the length of the number changes @Timon Bohn? If so, you can compute the new cursor position and set the TextField's cursor position in the TextFieldValue you pass in
(You would check and see if you're adding text before the cursor, and if so subtract the amount you're adding from the cursor position)
It's not intuitive, but if you set the selection range start and end to the same position it apparently represents the cursor being at that position
t

Timon Bohn

03/01/2021, 9:30 PM
Thank you @Daniel I’ll look into it!
👍 1
6 Views