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

Please add onFormattedUpdate() callback #2

Open
timothytripp opened this issue Jun 17, 2022 · 2 comments
Open

Please add onFormattedUpdate() callback #2

timothytripp opened this issue Jun 17, 2022 · 2 comments

Comments

@timothytripp
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Because the onEndEditing callback is not getting invoked until after the TextInput component loses focus, my app was attempting to save the contents of the form before the onEndEditing was called, so the formatted result was not coming in. For my use, I added another callback comparable to onValueUpdate() called onFormattedUpdate(). I also fixed a small error where you didn't provide the onValueUpdate as a useEffect dependency.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-intl-phone-field/src/index.tsx b/node_modules/react-native-intl-phone-field/src/index.tsx
index af9a955..25f22d7 100644
--- a/node_modules/react-native-intl-phone-field/src/index.tsx
+++ b/node_modules/react-native-intl-phone-field/src/index.tsx
@@ -16,6 +16,7 @@ export type IntlPhoneFieldProps = {
   defaultValue?: string;
   defaultFlag?: string;
   onEndEditing?: Function;
+  onFormattedUpdate?: Function;
   onValidation?: Function;
   onValueUpdate?: Function;
   containerStyle?: object;
@@ -30,6 +31,7 @@ let resolveFlagTimeoutId: NodeJS.Timeout;
 export default function IntlPhoneField({
   flagUndetermined = '❓',
   onEndEditing,
+  onFormattedUpdate,
   onValidation,
   onValueUpdate,
   defaultCountry,
@@ -112,7 +114,11 @@ export default function IntlPhoneField({
 
   useEffect(() => {
     onValueUpdate && onValueUpdate(value);
-  }, [value]);
+  }, [onValueUpdate, value]);
+
+  useEffect(() => {
+    onFormattedUpdate && onFormattedUpdate(formatted);
+  }, [onFormattedUpdate, formatted]);
 
   return (
     <View style={[styles.container, containerStyle]}>

This issue body was partially generated by patch-package.

@fakeheal
Copy link
Owner

Thank you so much for both your sponsorship and contribution! Over the next week I will implement & test the changes you suggested!

@fakeheal
Copy link
Owner

fakeheal commented Jul 6, 2022

@timothytripp Hi, it's me again. Could you post an example (on expo if possible) that shows the issue you're having with onEndEditing. Is your app auto saving the contents of the field without any user interaction?

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

2 participants