youjinp / SwiftUIKit

A collection of missing SwiftUI components
MIT License
278 stars 32 forks source link

Issue with regional settings different from US #17

Closed alphadogbkbone closed 3 years ago

alphadogbkbone commented 3 years ago

I'm not sure if it's a known bug but when region is not US, for example in Brazil where currency is R$ 999.999,99 the decimal place divider (, colon) is not allowed to be typed, only accept . dot and when you change to other field it displays correctly but maximum amount is 9.999 without decimal places. Could you please let me know if is there any workaround into your pack documentation ? I could not locate into the code.

Simulator Screen Shot - iPhone 12 - 2020-11-21 at 23 36 11 Simulator Screen Shot - iPhone 12 - 2020-11-21 at 23 31 37

youjinp commented 3 years ago

Hi, is the first image the desired output and the second one using SwiftUIKit?

Currently SwiftUIKit manually parses the input for the decimal points (e.g. line 338) so if you want to use "," for the decimal point, that will have to be built into SwiftUIKit.

If you need this urgently, I'd recommend you fork this library, and make changes to lines:

338: let tok = components(separatedBy:".")

353: return decimals.components(separatedBy: ".")[0]

357: let split = decimals.components(separatedBy: ".")

381: let formatter = Formatter.currency

to suit the Brazillian currency format.

Otherwise I'll add some configuration options when I get some free time!

Thanks!

alphadogbkbone commented 3 years ago

I did the changes suggested and the formatter.locale = NSLocale.currentLocale() is the default, this is why when I change to other field, the currency displays correctly in bra reais. The issue is when entering data where if I start typing 1234 when I type 1 the R$ symbol appears as expected then I continued typing, when I type 4, changes to R$ 1.234 and when I type 5 it disappears and display R$ 1 and if I keep typing when I type 8 it appears R$ 1.678 and when type 9 disappear and appear R$ 2. If I type something and try to enter the colon nothing happens. If I type a number for example 12 and try to type dot also nothing happens (probably due to the changes suggested. If you have any other place on the code so I can change and test will be really helpful because using the US region on the phone it works great.

Thanks in advance.

Best regards,

Edu

youjinp commented 3 years ago

Hi Edu, this should be fixed in v0.0.14. Thanks for reporting!

alphadogbkbone commented 3 years ago

Hello my friend. Thanks for the heads-up. I'm testing and it's working perfectly. That's great. Congrats my good friend.