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

PhoneNumberKit as init parameter #104

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

thedemonswithin
Copy link

@thedemonswithin thedemonswithin commented May 28, 2024

Passing PhoneNumberKit via init param, this can be useful in some cases. Also updated min version of PNK.

- pass PhoneNumberKit via init
@MojtabaHs
Copy link
Owner

Thank you for your contribution! Generally, it's not a good practice to expose the initializer of the reference type, outside of the Representable. Can you please suggest some simple use-case examples of this change which is not achievable with the current API?

@thedemonswithin
Copy link
Author

In my use case I need to restrict country code picker for only few countries, that allowed by rest api. This api provides only number prefixes (7, 20, 41, etc). I can import PhoneNumberKit and create another one instance to get country codes by their phone prefix. But as been stated in marmelroy's readme:

A PhoneNumberKit instance is relatively expensive to allocate (it parses the metadata and keeps it in memory for the object's lifecycle), you should try and make sure PhoneNumberKit is allocated once and deallocated when no longer needed.

And i'd prefer to create it once, pass to the view and use for another purposes, described before.
Screenshot for example
Screenshot 2024-05-29 at 15 05 42

@MojtabaHs
Copy link
Owner

MojtabaHs commented May 29, 2024

The issue is about keeping the reference in the UIViewRepresentable, How about this instead:

iPhoneNumberField(text: $text) {
    $0.phoneNumberKit = myCustomKit // 👈 Pass it in here
}

You can also customize the $0.phoneNumberKit directly without any need to pass in a custom kit.

Using `insertText` in case when `text` has initial value
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

Successfully merging this pull request may close these issues.

2 participants