Giter VIP home page Giter VIP logo

xcarpentier / react-native-country-picker-modal Goto Github PK

View Code? Open in Web Editor NEW
1.1K 19.0 777.0 12.09 MB

🇦🇶 Country picker provides a modal allowing a user to select a country from a list. It display a flag next to each country name.

Home Page: https://reactnative.gallery/xcarpentier/country-picker

License: MIT License

JavaScript 17.36% TypeScript 82.64%
country-picker countries react-native modal

react-native-country-picker-modal's Introduction

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!

react-native-country-picker-modal's People

Contributors

6pm avatar amit755 avatar ankitmaloo avatar arminsalcin avatar arthurvi avatar ayozemr avatar blankse avatar danzheng1993 avatar darwin-ming avatar dependabot[bot] avatar ianlin avatar iraycd avatar is343 avatar jonathanpalma avatar kerumen avatar mattinasi avatar mavenic avatar osdiab avatar pcarion avatar pnakibar avatar r0b0t3d avatar rafaelsevla avatar ratson avatar saxenanickk avatar sprmn avatar vitalik7 avatar wardoost avatar wildseansy avatar xcarpentier avatar xiqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-country-picker-modal's Issues

Only seeing 3 countries, no grey box with country info and no search filter.

As seen in the example it shows a lot more than three countries which is all i'm seeing; Canada, Mexico and the United States. Also in the example, after the country is selected a grey box with the selected country's info is displayed below. I don't know if that feature was taken out but i think it was pretty cool. I am also not seeing the country code that starts a country phone number. Finally as i red through the issue i saw that someone recommended a search filter which i also saw that another person made a PR for it so i'm not sure if it was accepted and merge but i am not seeing it when i load the app.

My Versions

CountryPicker: "0.0.1",
react: "16.0.0-alpha.12",
react-native : "0.45.1",
react-native-country-picker-modal : "0.3.0-rc1",
react-native-device-info: "^0.10.2"

Modal opens very slow

When pressing the flag to open the modal, it takes almost seconds before the modal is rendered. I just experimented a bit with the component to see what can be done to improve the performance. When we use a ListView instead of a ScrollView the modal renders almost instantly.
Also we can tweak the performance in RN 0.23 with the new < Incremental >

What do you think about using a ListView?

Add a license file to the repo

Although the package.json specified the license as MIT but there is not license file in the repo and I am not able to get the exact license text to ship with my app. Mainly, there are some placeholders that need to be filled in the license such as the year and the copyright holders which I can't fill myself. It would be great if you could add a LICENSE file to the repo.

NPM package breaks with React v16.0.0 and up

Problem Description

The current npm package is not up to date with the master branch. It imports PropTypes from 'react' which is no longer the correct package for react v16 and up.

Proposed Solution

The master branch does include logic to conditionally import PropTypes from the correct package ('react' or 'prop-types') depending on your setup. All that is needed is to update the npm package so that it includes the changes currently available on the master branch.

It may be a good idea to automate this process to prevent this from happening in the future.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

Letters are very hard to press on small screens

Testing on an iPhone 5s and the letters are almost impossible to press always takes the flag beside the letter.
Is there a way to give the letters some padding or margin left so the touchable of the flag doesn't get pressed.

If the device font is enlarged flags will be cut.

refresh if properties have changed

As the state of the component is set in the constructor, the component won't update if the parent component refreshes and updates the properties of CountryPicker.

For instance, if the containing page is first rendered with cca2 set to '' and then, after a network call for instance, the page is rendered again and sets this time cca2 to 'FR', the flag won't refresh as the internal state of cca2 is still set to ''.

The fix would be to move the initializations made in the ctor into the render method so that CountryPicker always reread its props before computing its internal state.

Nice work with this component. Very useful.

How to style the country-picker?

I'm aware that there is a<style> prop and CountryPicker.style.js which i can override. But can someone give me an example on how i can override these styles?

I tried something like this:

countrystyle: [{
     emojiFlag: {
        alignItems: 'center',
        justifyContent: 'center',
        fontSize: 12,
        width: 30,
        height: 30,
        borderColor: 'transparent',
        backgroundColor: 'transparent'
      },
      }],

but it gives me an error.

image

Any ideas? Thanks in advance.

Released code

The latest released version of this repo is v0.2.10 - where can I find the code that supports that version? The latest tag I see is v0.2.3.

add a close button

I think it would be nice to have a close button. A user should not be obligated to select a country in order to close the modal when he/she would like to cancel / go back. It is not a lot of work to add a button to the top left that sets the modalVisible boolean of the state to false.

The Screen will be stuck,when first scroll to 30th item

In the CountryPicker.js, I find this code:

initialLIstSize={30}

Perhaps because of device performance limit, when first scroll to 30th item,
the rest of the data is not loaded, so it stuck : (

Is there anyway to improve efficient?

stuck device: iPad 2, iPad mini.

Thanks.

'getAllCountries' is undefined

Hi i need to get the calling code by country (i have the country) before select any country from the list.
I follow the github example and try to import:
import CountryPicker, {getAllCountries} from 'react-native-country-picker-modal';
But i got 'getAllCountries' undefined in console.
There is other way to get the calling code?

Purpose of ref

Line 67 of master/example/Example.js includes a 'ref' parameter:

<CountryPicker
ref={(countryPicker) => { this.countryPicker = countryPicker; }}

What is its purpose?

I realise this is a question, not an issue. I guess the issue is missing documentation. :)

Contributing to project

hi guys.
I am using react-native-conuntry-picker-modal in my project
and I want to change some code to make a few styles correctable

but I'm not very familiar with yarn and expo. I have been just using npm intall and react-native run-ios or react-native run-android

so plz let me know how to run this project(example code) directly to change code easily
I forked this project and have in my local repositary

Flag not showing from beginning and after selecting

After I import this package and using the exact same code given in the example I cant see the selected flag, although i get the phone number changed, i get the list of flags in the picker menu, it is just grey where the flag should be. Screenshots included
c
cc

Dimensions error

Hello, the dimensions error still seems to be an issue. I see that it was supposed to be fixed in the closed issues, what happened?

It is not able to download package

I tried to download package with the following command.

npm i react-native-country-picker-modal --save

Error came up as below.

npm ERR! Command failed: git clone --template=.npm/_git-remotes/_templates --mirror git://github.com/niftylettuce/react-native-emoji.git.npm/_git-remotes/git-github-com-niftylettuce-react-native-emoji-git-e1715125
npm ERR! Cloning into bare repository '/Users/bykim/.npm/_git-remotes/git-github-com-niftylettuce-react-native-emoji-git-e1715125'...
npm ERR! fatal: unable to connect to github.com:

It seems like there is something wrong with
"react-native-emoji": "git://github.com/niftylettuce/react-native-emoji.git"

Chinese Translation is not working

It seems Chinese translation is not available, when I set zho as the translation language, it always output English instead.

But jpn works just fine.

I checked World Country data, it contains Chinese translation.

From Satyajit Sahoo

Looks great. Couple of suggestions,

  1. It's tedious to scroll to pick a country, there's should be a searchbar to filter (maybe even by short codes like IN)
  2. It's difficult to tap on the letters on the right, probably increase the area, can't increase or much vertically, but horizontally will be
    good
  3. The list items don't have anything feedback on press, some kinda feedback will be nice

world country data

Let me expose here a concern I have with the memory usage of the CountryPicker component and I am OK to tackle this issue and submit a PR if you think it is a valid concern.

Currently, you load the countries.json file from the world_country npm module, to get extra data from the selected country.

This file is big (444K) and it may be a waste of space considering that very few piece of information is needed from the file:

  • the cca2 code
  • the translation for the different names of the countries -to allow i18n of the country list (nice feature by the way)
  • the phone calling code (that's actually what I need in my app)
  • the name of the country
  • the currency

You already have a configuration file of yours (countryFlags.js) to store the image of the flags.

My suggestion would be to parse (offline) the countries.json and generate a local countryInfo.js file, that would be stored in your repo (with proper attribution to the author of world_country) with only the information needed in the context of your app.

This would require a few changes in the code (such as orderCountryList and getCountry) but nothing major and the footprint of the component in memory would be much smaller...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.