2.1.2 • Published 1 year ago

react-native-phonecode-picker v2.1.2

Weekly downloads
5
License
ISC
Repository
github
Last release
1 year ago

react-native-phonecode-picker

React Native components for picking phone number code. Supports 5 languages (Arab, German, French, Italian, Polish, Ukrainian, Russian, English, Spanish, Turkish)

Install

npm react-native-phonecode-picker --save

Minimum examples

import React, { useEffect, useState } from 'react';
import { View, Modal, SafeAreaView } from 'react-native';
import { PhoneInput, Countries, PhoneList } from 'react-native-phonecode-picker';

export const PhonePicker = () => {
    const [phone, setPhone] = useState('');
    const [country, setCountry] = useState({ countryName: '', phcode: '', key: '', mask: '', });
    const [visible, setVisible] = useState(false);

    useEffect(() => {
        const country = Countries.getCountryByIso('en', 'UA');
        setCountry(country);
    }, []);

    const onChooseCountry = (country: { countryName: string; phcode: string; key: string; mask: string; }) => {
        setCountry(country);
        setVisible(false);
    };

    return (
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 30 }}>
            <PhoneInput country={country} value={phone} onChangeText={setPhone} onPress={() => { setVisible(true) }} />
            <Modal visible={visible} animationType='slide'>
                <SafeAreaView style={{ flex: 1 }}>
                    <PhoneList language={'en'} onPress={onChooseCountry} isSearch={true} />
                </SafeAreaView>
            </Modal>
        </View>
    )
};

Examples

import { PhoneList } from 'react-native-phonecode-picker';

<PhoneList onPress={(country)=>console.log('country->', country)} language='en'/>

API

Language = 'ru' | 'es' | 'en' | 'ua' | 'ar' | 'de' | 'el' | 'fr' | 'it' | 'pl' | 'tr'

Countries

getCountries - returns countries array filtered by search.

Class type

interface ICountries {
    getCountries: (lang: Language, search?: string) => Array<Country>;
    getCountryByIso: (lang: Language, key: string) => Array<Country>;
    getCountryByPhoneCode: (lang: Language, key: string) => Country | undefined;
};

Usage example

console.log(CountriesApi.getCountries('en'));

Flags

getFlag - returns source flag by country key. getAllFlags - returns all source flag.

Class type

interface IFlags {
	getFlag: (key: string) => any;
	getAllFlags: () => object;
};

Usage example

<Image source={FlagsApi.getFlag('US')} resizeMode="stretch" style={{ width: 30, height: 30 }} />

PhoneList

Component props

interface Props {
        language: Language;
        isSearch?: boolean;
        onPress: (country: { countryName: string; phcode: string; key: string; mask: string; }) => void;
        containerStyle?: object;
        itemContainerStyle?: object;
        textStyle?: object;
        placeholder?: string;
    };

PhoneItem

Component props

interface Props {
        country: { countryName: string; phcode: string; key: string; };
        flag: sourseImage;
        testID: string;
        onPress: (country: { countryName: string; phcode: string; key: string; }) => void;
        itemContainerStyle?: object;
        textStyle?: object;
    };

PhoneInput

Component props

interface Props {
        country: { countryName: string; phcode: string; key: string; mask: string };
        onPress: () => void;
        value: string;
        onChangeText: (formatted: string, extracted: string | undefined) => void;
        style?: {
            container?: ViewStyle,
            flag?: ImageStyle;
            textInput?: TextStyle,
            textCode?: TextStyle,
            phoneCodeContainer?: ViewStyle,
            placeholderTextColor?: ColorValue,
        };
        inputProps: TextInputMaskProps;
        showFlag?: boolean;
    };

PhoneSearch

Component props

interface Props {
        searchString: string;
        onChangeText: (text: string) => void;
        placeholder?: string;
    };

License

ISC

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0-alpha

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago