3.4.2 • Published 8 months ago

@linhnguyen96114/react-native-phone-input v3.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

✨ Features

  • 📱 Cross-platform support (iOS & Android)
  • 🎨 Highly customizable UI
  • 🔍 Built-in country search
  • ✅ Google LibPhoneNumber validation
  • 🎯 TypeScript support
  • 🔄 Two flexible layouts
  • 🏳️ Country emoji flags support
  • 📞 Automatic country detection
  • 🎨 Dark theme support
  • 🔧 Extensive API

🚀 Installation

# Using npm
npm i @linhnguyen96114/react-native-phone-input

# Using yarn
yarn add @linhnguyen96114/react-native-phone-input

# For iOS
cd ios && pod install

💡 Examples

Basic Usage

import PhoneInput from '@linhnguyen96114/react-native-phone-input';

const BasicExample = () => {
  const [value, setValue] = useState('');

  return (
    <PhoneInput
      defaultValue={value}
      defaultCode="US"
      onChangeText={setValue}
      withShadow
      autoFocus
    />
  );
};

Custom Styled Input

const CustomStyledExample = () => {
  const [value, setValue] = useState('');

  return (
    <PhoneInput
      defaultValue={value}
      defaultCode="US"
      onChangeText={setValue}
      containerStyle={{
        width: '100%',
        borderRadius: 30,
        backgroundColor: '#fff',
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.1,
        shadowRadius: 3,
        elevation: 3,
      }}
      textContainerStyle={{
        borderRadius: 30,
        backgroundColor: '#fff',
        paddingHorizontal: 15,
      }}
    />
  );
};

Dark Theme

const DarkThemeExample = () => {
  const [value, setValue] = useState('');

  return (
    <PhoneInput
      defaultValue={value}
      defaultCode="GB"
      onChangeText={setValue}
      withDarkTheme
      containerStyle={{
        backgroundColor: '#2A2A2A',
        borderRadius: 12,
      }}
      textContainerStyle={{
        backgroundColor: '#2A2A2A',
        borderRadius: 12,
      }}
      textInputStyle={{
        color: '#fff',
      }}
    />
  );
};

Form Integration with Validation

const FormExample = () => {
  const [value, setValue] = useState('');
  const [valid, setValid] = useState(false);
  const phoneInput = useRef<PhoneInputRefType>(null);

  const checkValidation = () => {
    const isValid = phoneInput.current?.isValidNumber(value);
    setValid(isValid || false);
  };

  return (
    <PhoneInput
      ref={phoneInput}
      defaultValue={value}
      defaultCode="FR"
      onChangeText={setValue}
      onChangeFormattedText={(text) => {
        console.log('Formatted:', text);
      }}
      containerStyle={{
        width: '100%',
        borderRadius: 8,
        borderWidth: 1,
        borderColor: valid ? '#4CAF50' : '#dee2e6',
      }}
    />
  );
};

🛠️ Props

PropTypeDescription
withDarkThemebooleanEnable dark theme
withShadowbooleanAdd shadow effect
autoFocusbooleanAuto focus input
defaultCodeCountryCodeDefault country code
defaultCallingCodestringDefault calling code
valuestringControlled input value
defaultValuestringDefault phone number value
disabledbooleanDisable input
disableArrowIconbooleanHide the dropdown arrow icon
placeholderstringInput placeholder text
onChangeCountry(country: Country) => voidCallback when country changes
onChangeText(text: string) => voidCallback when input text changes
onChangeFormattedText(text: string) => voidCallback with formatted phone number
onBlur() => voidCallback when input loses focus
onFocus() => voidCallback when input gains focus
renderDropdownImageJSX.ElementCustom dropdown icon component
containerStyleStyleProp<ViewStyle>Container style
textContainerStyleStyleProp<ViewStyle>Text input container style
textInputPropsTextInputPropsAdditional TextInput props
textInputStyleStyleProp<TextStyle>Text input style
codeTextStyleStyleProp<TextStyle>Country code text style
flagButtonStyleStyleProp<ViewStyle>Flag button container style
countryPickerButtonStyleStyleProp<ViewStyle>Country picker button style
layout"first" \| "second"Layout style
filterPropsCountryFilterPropsCountry filter props
countryPickerPropsCountryPickerModalPropsCountry picker modal props
flagSizenumberSize of the country flag
showCountryCodebooleanShow the country code

🔧 Methods

MethodReturn TypeDescription
getCountryCodeCountryCodeGet the currently selected country code
getCallingCodeCallingCode \| undefinedGet the calling code for the selected country
isValidNumberbooleanValidate if the provided phone number is valid
getNumberAfterPossiblyEliminatingZero{ number: string; formattedNumber: string; }Get the phone number with leading zero removed if present

🤝 Contributing

Contributions are welcome! Please read our contributing guide to learn about our development process.

📝 License

This project is MIT licensed.


3.4.2

8 months ago

3.4.1

8 months ago

3.4.0

9 months ago

3.3.2

1 year ago

3.3.1

1 year ago

3.2.3

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.4

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago