Giter VIP home page Giter VIP logo

georgehop / react-native-country-codes-picker Goto Github PK

View Code? Open in Web Editor NEW
107.0 1.0 63.0 380 KB

⚡ ⚡ ⚡This lib. provide multi lang. country picker 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.⚡ ⚡ ⚡

Home Page: https://github.com/GeorgeHop/react-native-country-codes-picker

License: MIT License

TypeScript 100.00%
react-native picker country codes multilanguage search expo ios android country-codes

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

Hello there 👋

🏄 I'm George, a react-native mobile developer from Ukraine currently living in Poland
🏉 Creator, Traveler, Photographer

🎸 Side project

MCircle app - money managment social network

react react



I also have my own project where I have done everything by myself from the begining, moneymanagement application. You can check it by link below. For now we working in a team in 2 people. If you want to work with us feel free to write me on linkedin.

❗❗❗ We searching for new members ❗❗❗

🙌🏼 Open source

As a full stack developer I contributed on different projects like:

⚡️ Expertise

react

react

react

react-native

redux

react

react

react



💬 Get in touch

linked-in

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

Contributors

alotaibi1217 avatar asdotdev avatar bjorgar avatar brams-s avatar dbrab avatar einsight04 avatar elchawich avatar enlcy avatar erdogansad avatar gbyesiltas avatar georgehop avatar gonalc avatar henrikbn avatar johnf avatar kasperkberg avatar klethor avatar krisisav avatar louismonteiro avatar rafaelamanta avatar rrasconc avatar sheharyar566 avatar stuartrapop avatar zrapar 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

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

Typescript Declarations?

Could not find a declaration file for module 'react-native-country-codes-picker/components/CountryPicker'.

TS error in Flatlist ListHeaderComponent

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I couldn't spent much time on fixing this ts error, hence i just ignored the line which is causing the ts error.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-country-codes-picker/index.tsx b/node_modules/react-native-country-codes-picker/index.tsx
index 1d2131f..fc7e6e2 100644
--- a/node_modules/react-native-country-codes-picker/index.tsx
+++ b/node_modules/react-native-country-codes-picker/index.tsx
@@ -394,6 +394,7 @@ export const CountryList = ({
             style={[style?.itemsList]}
             keyboardShouldPersistTaps={'handled'}
             renderItem={renderItem}
+            // @ts-ignore
             ListHeaderComponent={(popularCountries && ListHeaderComponent && !searchValue ) &&
                 <ListHeaderComponent countries={preparedPopularCountries} lang={lang}/>}
             {...rest}

This issue body was partially generated by patch-package.

Feature request - Flag component

Expose the flag component separately. This will help user to create a button with flag and country name, upon touch open the country picker

Unit Testing with Jest to take a snapshop.

Hello, I was trying to make a snapshop using Jest but it's throwing me this error:

Screen Shot 2022-12-20 at 1 26 54

this is my snapshop:

import React from 'react';
import Phone from '../../../components/storyBook/components/inputs/Phone';
import renderer from 'react-test-renderer';

test('renders correctly', () => {
  const tree = renderer
    .create(
      <Phone
        onCountryCodeChange={() => {}}
        inputValue={''}
        onChangeText={() => {}}
        inputIsDisabled={false}
        floatingLabelText={'Label'}
        inputIsInValid={false}
      />,
    )
    .toJSON();
  expect(tree).toMatchSnapshot();
});

and this is my react component:

        <View>
          <CountryPicker
            lang="es"
            show={show}
            onBackdropPress={() => setShow(false)}
            pickerButtonOnPress={item => {
              setCountryCode(item.flag + ' ' + item.dial_code);
              onCountryCodeChange?.(item.flag + ' ' + item.dial_code);
              setShow(false);
            }}
            inputPlaceholder={'Selecciona tu país'}
            searchMessage={'Lo sentimos, no pudimos encontrar tu país'}
          />
        </View>

any suggestions on how to fix this issue?
"react-native": "0.68.2",
"react-native-country-codes-picker": "^2.2.0",

Please update the import code in guide

The code in guide:
import {CountryPicker} from "react-native-country-codes-picker";
is unable to import the library component onto the required screen. Because the component is exported by default, I used,
import CountryPicker from "react-native-country-codes-picker";
and it worked. I think updating the library will help others, Thank you.

How to preselect a country

We are going to detect user's locale and based on that we need to populate the initial value of the Country Picker. Is there a way to do this?

Issue with lint

Getting this error:
node_modules/react-native-country-codes-picker/index.tsx(16,33): error TS7016: Could not find a declaration file for module './helpers/useKeyboardStatus'. '/Users/../../node_modules/react-native-country-codes-picker/helpers/useKeyboardStatus.js' implicitly has an 'any' type.

Not sure how to fix it! Can anyone help with this?

Ts error in CountryPicker

the given type for the CountyPicker is a following,

interface Props {
excludedCountries?: string[],
showOnly?: string[],
popularCountries?: string[],

style?: Style,

show: boolean,
enableModalAvoiding?: boolean,
disableBackdrop?: boolean,

onBackdropPress?: (...args: any) => any,
pickerButtonOnPress: (item: CountryItem) => any,
itemTemplate?: (props: ItemTemplateProps) => JSX.Element,
ListHeaderComponent?: (props: ListHeaderComponentProps) => JSX.Element,
onRequestClose?: (...args: any) => any,

lang: string,
inputPlaceholder?: string,
inputPlaceholderTextColor?: TextStyle['color'],
searchMessage?: string,
androidWindowSoftInputMode?: string,
initialState?: string,

}

Now, As I my writing test in my application where I have used this CounteryPicker component, so, I have to test this CountryPicker for that I have find the element of the text input from where I can search the country and then select that country, so for that I have to pass testId to the textInput, the type of CountryPicker does not have the testID props but If I am passing it forcefully than I works.

Warning when scrolling the list

 WARN  Please report: Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native code: {"15204":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15207":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15210":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15213":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15216":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15219":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15222":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15225":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15228":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15231":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15234":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15237":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15240":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15243":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15246":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15249":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15252":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15255":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15258":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15261":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15264":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15267":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15270":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15273":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15276":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15279":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15282":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15285":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15288":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15291":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15294":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15297":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15300":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15303":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15306":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15309":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15312":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15315":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15318":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15321":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15324":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15327":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15330":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15333":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15336":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15339":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15342":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15345":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15348":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"15351":{"module":"NativeAnimatedModule","method":"startAnimatingNode"},"...(truncated keys)...":451}
  • Just scroll the list to the very end.

iPhone 12 Pro, iOS 16.3.1
Expo SDK 48
Expo Go

Disable Picker

Please do let me know if there's a way to enable / disable the actual picker.

Want to Customize the flag

I want to customize the flag and want to make it circular, but though I'm receiving flag in Text Component, so I'm no able to customize it

Improvement suggestions

Just some minor suggestions (I can make a PR for this if needed):

  1. Export the types and CountryButton Component at top level (in index.ts). Makes it easier to use the library
  2. Correctly type ListHeaderComponent with ({countries: CountryItem[], locale: string}) => JSX.Element To avoid TS false-errors when using the library.

Element type is invalid

Hello,
I try to use the library in my app, but when I run I get this message:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

I also tried to import into my APP with this line: import CountryPicker from "react-native-country-codes-picker ";
but in this case I get this message: Error: text strings must be displayed inside a component.

Has anyone encountered the same problem?
Can you help me?

Code for the example GIF

Firstly, this library is awesome.
I was wondering if you have the exact code for the example GIF you have in the README? I love the search feature and the collapsible context menu list, I'm struggling to replicate it :). (Currently my implementation takes the entire screen :( )

can't avoiding keyboard with enableModalAvoiding

code:

<CountryPicker
      show={show}
      enableModalAvoiding
      style={{
        modal: {height: '50%'},
      }}
      onBackdropPress={() => setShow(false)}
      pickerButtonOnPress={item => onPickCountry(item)}
    />

i was using enableModalAvoiding but it not work in my project

IOS: 16.1 , Simulator : Iphone 14

keyboard not hiding on country code select

Greetings,

I'm currently using the CountryPicker in our project, and it's generally functioning as expected. However, there's a specific scenario that requires attention. Here's how it plays out:

  1. Upon clicking the button, the CountryPicker opens, and the list of countries populates. I can select my preferred country code by clicking on an item from the list.
  2. After making a selection, the CountryPicker modal is dismissed or hidden.

The issue arises when I click on the input box to search for a country among the available options. When I click on an item in the list that appears after the search, there's an unexpected behavior. On the first click, the keyboard gets dismissed, and I need to click again to select the desired country. This means I have to click twice to make a country selection.

This behavior is somewhat cumbersome and could benefit from a smoother interaction. We appreciate your attention to this matter as it affects the usability of the CountryPicker component. Thank you for considering this feedback.

here is the code
`
const handlePickerPress = item => {
setCountryCode(item.dial_code);
setFlag(item.flag);
setShow(false);
Keyboard.dismiss();
if (onPress) {
onPress(item);
}
};
<TouchableOpacity
onPress={() => setShow(true)}
style={{
alignSelf: 'center',
}}>
<Text
style={{
color: '#1b1212',
fontSize: 14,
marginRight: 10,
marginLeft: 10,
}}>
{countryCode}

          <CountryPicker
            searchMessage={'Search here'}
            show={show}
            style={{
              // Styles for whole modal [View]
              modal: {
                height: 425,
                //backgroundColor: 'red',
              },
              // Styles for modal backdrop [View]
              backdrop: {
                backgroundColor: 'transparent',
              },

              textInput: {
                height: 45,
                //borderRadius: 20,
                color: '#1b1212',
              },
              countryName: {
                color: '#1b1212',
                fontFamily: 'Mont-Regular',
                lineHeight: 16,
                fontSize: 14,
              },
              dialCode: {
                color: '#1b1212',
                fontFamily: 'Mont-Regular',
                lineHeight: 16,
                fontSize: 14,
              },
              countryButtonStyles: {
                height: 50,
                //backgroundColor:'#f3f3f3'
              },
            }}
            pickerButtonOnPress={handlePickerPress}
            onRequestClose={() => {
              setShow(false);
            }}
     />

`

Typescript Support

Hi there,

Any update regarding adding the typescript support to the package? If you need some help, do let me know and we can discuss.

Handle Back button press

Description

When the back button is pressed, nothing happen which feels like the application is buggy.

Problem

When a Modal is opened, BackButton events are not propagated. As this component is using a Modal, developers cannot catch this event

Solution

Close the modal when the back button is pressed

import { BackHandler } from "react-native";

// Add handleBackButton to props

useEffect(() => {
  let backHandler: NativeEventSubscription;
  if (handleBackButton) {
    backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
      closeModal();
    });
  }

  return () => {
    backHandler?.remove();
  };
}, [handleBackButton]);

Unable to resolve module ./components/CountryPicker

After installing the library and opening the app i got this error on app startup
after checking the files i found that CountryPicker and CountryButton are in jsx format which is not supported, changing the formats to JS or TS fixes it
RN version: 0.68.1
simulator_screenshot_95828E37-FA5F-4C7E-961E-9F56A0F9262B
p

enableModalAvoiding with "Modal Height" not Working

when enableModalAvoiding={true} and you specify the "height" property in the Modal style, the keyboard avoiding view stops working. If you remove the "height" value (from below) it starts working again.

style={{
modal: {
height: 250,
},
}}

Dropdown for language only with flags

This package looks great. Thank you.

it would be great to have a second drop down component for choosing languages styled the same way. Same concept - flag on left with language displayed based on currently selected language.

Background color is still white on dark mode

I found a problem that on light mode, the background color is white and text is dark. But when switch to dark mode, background color is still white but text color is change to white. Great work, thank you so much!

missing placeholderTextColor

Hi, in React Native ver. > 0.69.0 it is necessary to specify the placeholderTextColor field in the TextInput component, only in this way the placeholder will be visible. Thanks a lot.
image

Search input should accept country names ignoring letter accents.

I was searching for mexico, but I could not see any result. So, the thing is that I need to search it exactly like ''méxico'' with the ''é'' being accented.

I think it would be nice if we can ignore the accents on the search query for a better user experience.

I fixed this issue by modifying the next lines 119 and 122 in index.tsx

const resultCountries = React.useMemo(() => {
    const lowerSearchValue = searchValue.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");

    return codes.filter((country) => {
        if (country?.dial_code.includes(searchValue) || country?.name[lang || 'en'].toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").includes(lowerSearchValue)) {
            return country;
        }
    });
}, [searchValue]);

I needed to add .normalize("NFD").replace(/[\u0300-\u036f]/g, "") to ignore all accents in search query.

Could this solution be added in the main branch?

Update package

Hi,
Thanks for the work! Very much appreciated!

I created a pull request to only show popular countries if there is no searchValue. As long as the popular countries doesn't filter when searching, I would prefer them to go away. Possible to merge that (if it looks ok), and update the package with the types-fixes done 3 weeks ago as well?

Mobile number templet

Kindly add mobile number templet based on country, so we can display as place holder in textinput

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.