• Stars
    star
    1,071
  • Rank 43,174 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ‡ฆ๐Ÿ‡ถ Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name.

Country Picker for React Native.

iOS Android Web

Demo

Installation

$ yarn add react-native-country-picker-modal

Basic Usage

For more complete example open App.tsx

import React, { useState } from 'react'
import { View, Text, StyleSheet, PixelRatio, Switch } from 'react-native'
import CountryPicker from 'react-native-country-picker-modal'
import { CountryCode, Country } from './src/types'

const styles = StyleSheet.create({
  // ...
})

export default function App() {
  const [countryCode, setCountryCode] = useState<CountryCode>('FR')
  const [country, setCountry] = useState<Country>(null)
  const [withCountryNameButton, setWithCountryNameButton] = useState<boolean>(
    false,
  )
  const [withFlag, setWithFlag] = useState<boolean>(true)
  const [withEmoji, setWithEmoji] = useState<boolean>(true)
  const [withFilter, setWithFilter] = useState<boolean>(true)
  const [withAlphaFilter, setWithAlphaFilter] = useState<boolean>(false)
  const [withCallingCode, setWithCallingCode] = useState<boolean>(false)
  const onSelect = (country: Country) => {
    setCountryCode(country.cca2)
    setCountry(country)
  }
  return (
    <View style={styles.container}>
      <Text style={styles.welcome}>Welcome to Country Picker !</Text>
      <Option
        title='With country name on button'
        value={withCountryNameButton}
        onValueChange={setWithCountryNameButton}
      />
      <Option title='With flag' value={withFlag} onValueChange={setWithFlag} />
      <Option
        title='With emoji'
        value={withEmoji}
        onValueChange={setWithEmoji}
      />
      <Option
        title='With filter'
        value={withFilter}
        onValueChange={setWithFilter}
      />
      <Option
        title='With calling code'
        value={withCallingCode}
        onValueChange={setWithCallingCode}
      />
      <Option
        title='With alpha filter code'
        value={withAlphaFilter}
        onValueChange={setWithAlphaFilter}
      />
      <CountryPicker
        {...{
          countryCode,
          withFilter,
          withFlag,
          withCountryNameButton,
          withAlphaFilter,
          withCallingCode,
          withEmoji,
          onSelect,
        }}
        visible
      />
      <Text style={styles.instructions}>Press on the flag to open modal</Text>
      {country !== null && (
        <Text style={styles.data}>{JSON.stringify(country, null, 2)}</Text>
      )}
    </View>
  )
}

Props

  • countryCode: CountryCode
  • region?:Region
  • subregion?: Subregion
  • countryCodes?: CountryCode
  • theme?: Theme
  • translation?: TranslationLanguageCode
  • modalProps?: ModalProps
  • filterProps?: CountryFilterProps
  • flatListProps?: FlatListProps
  • withAlphaFilter?: boolean
  • withCallingCode?: boolean
  • withCurrency?: boolean
  • withEmoji?: boolean
  • withCountryNameButton?: boolean
  • withCurrencyButton?: boolean
  • withCallingCodeButton?: boolean
  • withFlagButton?: boolean
  • withCloseButton?: boolean
  • withFilter?: boolean
  • withFlag?: boolean
  • withModal?: boolean
  • visible?: boolean
  • containerButtonStyle?: StyleProp<ViewStyle>
  • renderFlagButton?(props: (FlagButton['props'])): ReactNode (FlagButton props)
  • renderCountryFilter?(props: CountryFilter['props']): ReactNode (CountryFilter props is TextInputProps)
  • onSelect(country: Country): void (Country)
  • onOpen(): void
  • onClose(): void
  • closeButtonImage?: ImageSourcePropType
  • closeButtonStyle?: StyleProp
  • closeButtonImageStyle?: StyleProp
  • disableNativeModal?: boolean (you have to wrap your all app with CountryModalProvider)
  • preferredCountries: CountryCode preferred countries they appear first (withAlphaFilter must be false)

Dark theme example

react-native-country-picker-modal-dark

A simple example to display a CountryPicker component with a dark theme.

import CountryPicker, { DARK_THEME } from 'react-native-country-picker-modal'

const MyDarkView = () => <CountryPicker theme={DARK_THEME} />

Dependencies

FAQ

Is it supported and tested both on android and iOS?

YES

Is the data that is populated inside the list saved offline once I install your package?

YES : It used the world-countries package and image is stored into json and base64.

Tiers lib using this lib

> Your project?

See also

Contribution

Questions

Feel free to contact me or create an issue

made with โ™ฅ

Licence

MIT

Hire an expert!

Looking for a ReactNative freelance expert with more than 12 years experience? Contact me from myย website!

More Repositories

1

rn-tourguide

๐ŸšฉMake an interactive step by step tour guide for your react-native app (a rewrite of react-native-copilot)
TypeScript
726
star
2

rn-pdf-reader-js

๐Ÿ“„ PDF reader in JavaScript only for Expo - Android & iOS capable
TypeScript
386
star
3

react-native-suggester

๐Ÿ”Ž React-Native package to decorate TextInput and get suggestions with good UX
TypeScript
58
star
4

react-native-slack-webhook

๐Ÿ’ฌ Follow some activities (new user, payment, ...) from your app via Slack and this webhook lib
Objective-C
55
star
5

gifted-chat-web-demo

Gifted chat web demo
TypeScript
44
star
6

react-native-safe-image

Really light React-Native package to handle fallback when image is on error
TypeScript
28
star
7

rn-verifcode

๐Ÿ”ข React-Native component to input confirmation code for both Android and IOS
TypeScript
25
star
8

vitrine

๐Ÿ–ผ vitrine: professional website and app showcase
TypeScript
18
star
9

clean-archi-boilerplate

clean-archi-boilerplate
TypeScript
10
star
10

rn-slideshow

๐ŸŒSlideshow with expo, theming, customizable footer, etc
TypeScript
7
star
11

react-redux-dispatch-async

๐ŸŽธ react-redux hook & redux middleware to be able to wait for async actions with fixed defined suffixes
TypeScript
7
star
12

bs-react-native-gifted-chat

๐Ÿ—๐Ÿ’ฌGifted Chat clone with Reason
JavaScript
6
star
13

redux-actions-ts

โš›๏ธ Redux-Actions with TypeScript helper package
TypeScript
4
star
14

find-emoji

๐Ÿ˜€ A simple mobile app to find the appropriate emoji!
JavaScript
3
star
15

mooditor

Mooditor, simple in browser markdown editor.
JavaScript
2
star
16

react-redux-dispatch-async-example

Created with CodeSandbox
TypeScript
2
star
17

ng-uri

A wrapper for URI.js
JavaScript
2
star
18

lbpt-website

Site en python + django pour Google App Engine pour une association
Python
2
star
19

breizhcamp

1
star
20

fibo-premier

experimentation with rust programming
Rust
1
star
21

prezmash

PrezMash : France 2012 presidential with Play!
Java
1
star
22

developers.scalingo.com

API documentation of Scalingo's platform
HTML
1
star
23

newbie

newbie
HTML
1
star
24

expo-notif

JavaScript
1
star
25

ng-spa

Formation AngularJS et industrialisation pour les dรฉveloppeurs front end
1
star