1.0.1 • Published 2 years ago

react-native-country-picker-samcodeng v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

react-native-country-picker-samcode

:zap: :zap: :zap: This lib. provide multi lang. country picker or country list with search functionality. Fully crossplatform and supported on React-native and expo. Didn't find your country ? Just add the required countries or locales and make a PR. :zap: :zap: :zap:

Coming soon :muscle: :pray:

  1. Custom search input rendering.
  2. Picker types (modal, input). If you need input with search.
  3. Docs update/improve for the best user experience.
  4. Animation improvements.

If you have something interesting ! Just write to us :)

:grey_exclamation: Installation :grey_exclamation:

expo: expo install react-native-country-picker-samcode
npm: npm i react-native-country-picker-samcode
yarn: yarn add react-native-country-picker-samcode

Example

ezgif com-gif-maker

Basic usage

Modal

import {CountryPicker} from "react-native-country-picker-samcode";

export default function App() {
  const [show, setShow] = useState(false);
  const [countryCode, setCountryCode] = useState('');

  return (
    <View style={styles.container}>
      <TouchableOpacity
        onPress={() => setShow(true)}
        style={{
            width: '80%',
            height: 60,
            backgroundColor: 'black',
            padding: 10,
        }}
      >
        <Text style={{
            color: 'white',
            fontSize: 20
        }}>
            {countryCode}
        </Text>
      </TouchableOpacity>

      // For showing picker just put show state to show prop
      <CountryPicker
        show={show}
        // when picker button press you will get the country object with dial code
        pickerButtonOnPress={(item) => {
          setCountryCode(item.dial_code);
          setShow(false);
        }}
      />
    </View>
  );
}

List

import {CountryList} from "react-native-country-picker-samcode";

export default function App() {
  const [countryCode, setCountryCode] = useState('');

  return (
    <View style={styles.container}>
      <View        
        style={{
            width: '80%',
            height: 60,
            backgroundColor: 'black',
            padding: 10,
        }}
      >
        <Text style={{
            color: 'white',
            fontSize: 20
        }}>
            {countryCode}
        </Text>
      </TouchableOpacity>

      // All props the same as for picker
       <CountryList
          lang={'pl'}
          pickerButtonOnPress={(item) => {
              setCountryCode(item.dial_code);
          }}
       />
    </View>
  );
}

Props

Below are the props you can pass to the React Component.

PropTypeDefaultExampleDescription
showbooleanThis prop using for displaying the modal. Put your show state here.
pickerButtonOnPressfunction(country) => setCode(country.dial_code)Put your function/functions here for getting country data from picker.
inputPlaceholderstringinputPlaceholder={'Your placeholder'}If you need a custom placeholder for your input you may need this prop.
searchMessagestringsearchMessage={'Some search message here'}If you want to customize search message just use this prop.
langstring'en'lang={'pl'}If you need to change the lang. just put one of supported lang. Or if you didn't find required lang just add them and make a PR :)
enableModalAvoidingbooleanfalseenableModalAvoiding={true}Is modal should avoid keyboard ? On android to work required to use with androidWindowSoftInputMode with value pan, by default android will avoid keyboard by itself
androidWindowSoftInputModestringandroidWindowSoftInputMode={'pan'}Basicaly android avoid keyboard by itself, if you want to use custom avoiding you may use this prop
itemTemplateReactNodeCountryButtonitemTemplate={YourTemplateComponentsHere}This parameter gets a React Node element to render it as a template for each item of the list. These properties are sent to the item: key, item, style, name, and onPress
styleObjectstyle={{yoursStylesHere}}If you want to change styles for component you probably need this props. You can check the styling part below.
disableBackdropbooleanfalsedisableBackdropif you don't wanna show modal backdrop pass this prop.
onBackdropPressfunctionnullonBackdropPress={() => setShow(false)}If you want to close modal when user taps on the modal background.
initialStatestringinitialState={'+380'}Sometimes you need to pre-select country for example by user current location so you may use this prop.
excludedCountriesarrayexcludedCountries={'RU', 'BY'}In this prop you can define list of countries which you want to remove by adding their codes.

:grey_exclamation: Also you can use all other FlatList and TextInput props if you need. :grey_exclamation:

Styling

<CountryPicker
    show={show}
    lang={'cz'}
    style={{
        // Styles for whole modal [View]
        modal: {
            height: 500,
            backgroundColor: 'red'
        },
        // Styles for modal backdrop [View]
        backdrop: {
        
        },
        // Styles for bottom input line [View]
        line: {
        
        },
        // Styles for list of countries [FlatList]
        itemsList: {
        
        },
        // Styles for input [TextInput]
        textInput: {
              height: 80,
              borderRadius: 0,
        },
        // Styles for country button [TouchableOpacity]
        countryButtonStyles: {
              height: 80
        },
        // Styles for search message [Text]
        searchMessageText: {

        },
        // Styles for search message container [View]
        countryMessageContainer: {
        
        },
        // Flag styles [Text]
        flag: {

        },
        // Dial code styles [Text]
        dialCode: {

        },
        // Country name styles [Text]
        countryName: {

        }
    }}
    pickerButtonOnPress={(item) => {
        setCountry(item.name.en);
        setShow(false);
    }}
/>

:crossed_flags: Supported langs. :crossed_flags:

  "name": {
    "en": "English",
  },

react-native-country-picker-samcodeng

react-native-country-picker-samcodeng

react-native-country-picker-samcodeng