Closed elitalon closed 7 months ago
Hey @elitalon Thanks for raising this issue.
After some investigation, including a lot of back and forward changes made in multiples PRs, I think I'm finally able to fix this issue regarding flag and partial formatter.
I'm gonna open a PR soon.
Thanks for the fix, @bguidolim! I upgrade PhoneNumberKit in our project and now it works as expected 👌🏼
Do you think it's still worth pursuing switching regional flags based on leading digits?
To be honest, I don't think so. It's quite tricky to make it generic considering so many different patterns you can find around the world. Since it's showing the right flag when the number is complete, I would say it's good enough.
Makes sense 👍🏼 Thanks!
New Issue Checklist
Steps to reproduce
PartialFormatter
instance with the default region set to"US"
formatPartial(_:)
with the value"+7"
currentRegion
Expected result
currentRegion
returns"RU"
.Actual result
currentRegion
returns"US"
.Note that when the default region is set to something other than
"US"
,currentRegion
returns"RU"
as expected. The following tests demonstrate this behaviour:The fact that the same input (
"+7"
) produces two different results depending on the default region seems an inconsistent behaviour. I think this was introduced in #689 by changing the waycurrentRegion
is resolved. If I revert that change, all tests above succeed.Also, I don't understand why a special case was introduced in
PartialFormatter
for Kazakhstan only. If I'm not mistaken there are other regions that share the same country code (e.g."+1"
or"+44"
) and have their own flag.I think #689 should be reverted until a more robust way of solving that "flag problem" is implemented. Ideally one that works in all cases, not just for Kazakhstan.
I'm happy to help with such implementation, but I would need guidance because my current knowledge of phone number metadata is a bit limited.
So far my initial idea is to start with how
currentMetadata
is updated inextractCountryCallingCode(_:)
. Right now the implementation usesmainTerritory(forCode:)
, but I wonder iffilterTerritories(byCode:)
could be used instead, picking a candidate based on something likeleadingDigits
:Environment
I'm integrating PhoneNumberKit through SPM in an iOS app.