🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-native-country-code-select

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-country-code-select

React Native component to select a country code

0.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

Country Code Select - Simform

react-native-country-code-select

npm version Android iOS MIT

This is a pure javascript library for selecting a country with search and filter functionality

This library is easy to use and provides you full customization, so you can customize component based on your need

🎬 Preview

SimformSolutionsSimformSolutions SimformSolutions

Quick Access

Installation | CountryPicker | Methods | Properties | Example | License

Installation

1. Install library, react-native-reanimated and react-native-gesture-handler
$ npm install react-native-country-code-select react-native-reanimated react-native-gesture-handler
# --- or ---
$ yarn add react-native-country-code-select react-native-reanimated react-native-gesture-handler
2. Install cocoapods in the ios project
cd ios && pod install

Note: Make sure to wrap your root component / entry point with GestureHandleRootView

import { GestureHandlerRootView } from 'react-native-gesture-handler';
export default const App = () => {
  return <GestureHandlerRootView>{/* content */}</GestureHandlerRootView>;
}

Note: Make sure to add Reanimated's babel plugin to your babel.config.js

  module.exports = {
      ...
      plugins: [
          ...
          'react-native-reanimated/plugin',
      ],
  };
Know more about react-native-gesture-handler, react-native-reanimated

Compatibility

Only supports react-native 0.62+

CountryPicker

🎬 Preview

Default CountryPicker

Basic usage

import React, { useState } from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { CountryPickerModal } from 'react-native-country-code-select';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

const App = () => {
  const [isVisible, setIsVisible] = useState(false);
  const [selectedValue, setSelectedValue] = useState({});
  return (
    <GestureHandlerRootView style={styles.container}>
      <View style={styles.viewStyle}>
        <Text style={styles.textView}>
          {JSON.stringify(selectedValue, null, 2)}
        </Text>
        <Text style={styles.separator}>{'-- --'}</Text>
        <TouchableOpacity
          activeOpacity={0.8}
          style={styles.selectCountryButton}
          onPress={() => setIsVisible((oldStatus) => !oldStatus)}
        >
          <Text style={styles.selectCountry}>Select Country</Text>
        </TouchableOpacity>
        <CountryPickerModal
          isVisible={isVisible}
          onClose={() => setIsVisible(false)}
          {...{ onSelect: setSelectedValue }}
        />
      </View>
    </GestureHandlerRootView>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#e6d7b8',
  },
  textView: {
    width: '60%',
    backgroundColor: '#261a08',
    padding: 20,
    borderWidth: 1,
    borderRadius: 20,
    overflow: 'hidden',
    color: '#ffffff',
    fontWeight: '500',
  },
  viewStyle: {
    justifyContent: 'center',
    alignItems: 'center',
    flex: 1,
  },
  selectCountryButton: {
    width: '60%',
    alignItems: 'center',
    justifyContent: 'center',
    paddingVertical: 15,
    backgroundColor: '#261a08',
    borderRadius: 20,
  },
  selectCountry: {
    color: '#ffffff',
    fontWeight: 'bold',
    fontSize: 16,
  },
  separator: {
    marginVertical: 20,
    letterSpacing: 2,
    fontSize: 15,
    fontWeight: 'bold',
  },
});

Selected Country Data

{
  name: string;
  flag: string;
  countryInitials: string;
  region: string;
  subregion: string;
  callingCode: string[];
  currency: string[];
}

Methods

NameDefaultType
Description
onClose*-functionClose modal callback function
onSelect*-functionSelect country callback function that returns the selected country

Props

NameDefaultType
Description
isVisible*falsebooleanHide / show country list modal
customBackImageSourceImageImageSourcePropTypeCustom close modal image source
customBackImageStyle{}ImageStyleClose modal image style
isFlagVisibletruebooleanIf false, Country flag will be hidden
isAlphabetsVisibletruebooleanIf false, Quick country fliter will be hidden
headerSearchPlaceholder"Enter Country"stringCustom search placeholder text
isSearchInputVisibletruebooleanIf false, Search input will be hidden
renderCustomSearchInput-functionRender custom search input
searchHeaderInputStyle{}ViewStyleSearch input style
isCloseButtonVisiblefalsebooleanIf true, Modal close button will be visible
searchHeaderProps{}TextInputPropsSearch input props
countryListTitleStyle{}TextStyleCountry name / title style
modalContentStyle{}ViewStyleModal content style
modalContainerStyle{}ViewStyleModal container style
customRowStyle{}ViewStyleCountry list item / row style
customAlphabetsStyles{}TextStyleQuick filter (A-Z) text style
customAlphabetContainerStyles{}ViewStyleQuick filter (A-Z) container style
emptyTextOops, there is no country availablestringCustom message to show when there's no search result found
emptyTextStyle{}TextStyleCustom empty message style
emptyContainerStyles{}ViewStyleCustom empty message container style
renderCustomEmptyComponent-functionRender custom component when there's no search result found
customCloseButton-functionRender custom modal close button
renderSearchInputClear-functionRender custom cancel image in search input
handleStyle{}ViewStyleView style to be applied to the handle bar component
handleComponent-functionRender custom handle bar component

Example

A full working example project is here Example

$ yarn
$ yarn example ios   // For ios
$ yarn example android   // For Android

Find this library useful? ❤️

Support it by joining stargazers for this repository.⭐

Bugs / Feature requests / Feedbacks

For bugs, feature requests, and discussion please use GitHub Issues, GitHub New Feature, GitHub Feedback

🤝 How to Contribute

We'd love to have you improve this library or fix a problem 💪 Check out our Contributing Guide for ideas on contributing.

License

  • MIT License

Keywords

react

FAQs

Package last updated on 12 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts