Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to separate a PhoneNumber's country prefix from the rest #32

Closed
AliSoftware opened this issue Mar 15, 2016 · 6 comments
Closed

Allow to separate a PhoneNumber's country prefix from the rest #32

AliSoftware opened this issue Mar 15, 2016 · 6 comments

Comments

@AliSoftware
Copy link

It would be cool to be able to separate a PhoneNumber's intl prefix from the rest of the phone number, e.g. for a french phone number, "0612345678" would give the tuple ("+33", "612345678")

This would have multiple applications and possibilities, one of them being to allow the user to select a country in one way, the UI then displaying the selected intl prefix, and let the user enter the rest of the phone number in a TextField then.

Application for PhoneNumberTextField

One UI we want to implement is adding a leftView to the PhoneNumberTextField containing an UIButton. On tap, this will display a UIPickerView to select the country, and upon selecting one will display e.g. 🇫🇷 (+33) in the button's title.
Then the PhoneNumberTextField should be able to format the reminder of the phone number taking that fixed country prefix into account

Application for UILabel

In another place in our UI, we need to simply display the phone number, but we may still need to split it for display and layout purposes in two separate labels (e.g. one label in gray text containing the prefix "+33" and another label next to it in black containing the rest)

So this request of being able to split the PhoneNumber is not limited to PhoneNumberTextField, but should also be made accessible for other purposes and customization as well (maybe make func adjustedNationalNumber() public instead of private to solve that?)

@sentiasa
Copy link

Your approach (having UIPickerView on the left of PhoneNumberTextField). If you can achieve what you are trying, I'd be grateful to read a mini-walkthrough from you. That would be amazing if you can write it here, below..

@marmelroy
Copy link
Owner

@sentiasa, @AliSoftware's UI approach for phone number entry is quite common and something PhoneNumberKit should support out-of-the-box.

Some modifications to PhoneNumberTextField and the ParialFormatter are necessary to allow it to do partial formatting for international dialling with a locked country region.

I'm hoping to push the modifications and an example app implementing this pattern next week.

@marmelroy
Copy link
Owner

Re the UILabel application - I just pushed an update to the formatter that allows you to format parsed phone numbers while excluding the prefix:
0742c0d

So for example:

phoneNumber.toInternational(false) // "6 89 55 55 55"
phoneNumber.toE164(false) // "689555555"

@sentiasa
Copy link

@marmelroy That would be interesting to see an example app on using @AliSoftware 's UIPicker & flags approach

@marmelroy
Copy link
Owner

Resolved by 40ff2f4

An example project will be added before this is packaged in a release...

Basically, I added a withPrefix optional Bool on PhoneNumberTextField that works as expected.

@sentiasa
Copy link

@marmelroy Please drop here a message too when the demo get added. Seeing flags with PhoneNumberKit would be very interesting to see.. Thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants