npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-phone-input2

v0.1.0

Published

Phone input box for React Native

Downloads

120

Readme

React Native Phone Input

Phone input box for React Native

The original lib thegamenicorus/react-native-phone-input used an old version of google-libphonenumber, which has some bugs when validate the phone number starting with +86199.

|2560-02-07 01_32_33|2560-02-08 00_04_18| |---------------|----------|

Installation

npm i react-native-phone-input --save

Basic Usage

import PhoneInput from 'react-native-phone-input'

render(){
    return(
        <PhoneInput ref='phone'/>
    )
}

see full basic example

Custom Your Own Picker

|2560-02-08 01_10_22|2560-02-08 01_46_21| |---------------|----------|

  1. in componentDidMount, keep this.phone.getPickerData() in state
  2. create function for open your modal (onPressFlag in example)
  3. <PhoneInput onPressFlag={function in 2.} />
  4. call this.phone.selectCountry for set country of <PhoneInput />
componentDidMount(){
    this.setState({
        pickerData: this.phone.getPickerData()
    })
}

onPressFlag(){
    this.myCountryPicker.open()
}

selectCountry(country){
    this.phone.selectCountry(country.iso2)
}

render(){
    return(
        <View style={styles.container}>
            <PhoneInput
                ref={(ref) => { this.phone = ref; }}
                onPressFlag={this.onPressFlag}
            />

            <ModalPickerImage
                ref={(ref) => { this.myCountryPicker = ref; }}
                data={this.state.pickerData}
                onChange={(country)=>{ this.selectCountry(country) }}
                cancelText='Cancel'
            />
        </View>
    )
}

see full custom picker example

Custom Library Picker

use awesome react-native-country-picker-modal to select country

|2560-02-08 02_26_20|2560-02-08 02_43_18| |---------------|----------|

onPressFlag(){
    this.countryPicker.openModal()
}

selectCountry(country){
    this.phone.selectCountry(country.cca2.toLowerCase())
    this.setState({cca2: country.cca2})
}

render(){
    return(
        <View style={styles.container}>
            <PhoneInput
                ref={(ref) => { this.phone = ref; }}
                onPressFlag={this.onPressFlag}
            />

            <CountryPicker
                ref={(ref) => { this.countryPicker = ref; }}
                onChange={(value)=> this.selectCountry(value)}
                translation='eng'
                cca2={this.state.cca2}
            >
                <View></View>
            </CountryPicker>
        </View>
    )
}

see full custom library picker example

Custom Countries

<PhoneInput
  countriesList={require('./countries.json')}
/>

Configuration

Properties:

| Property Name | Type | Default | Description | |---------------|----------|-------------|----------------------------------------------------------------| | initialCountry | string | 'us' | initial selected country | | allowZeroAfterCountryCode | bool | true | allow user input 0 after country code | | disabled | bool | false | if true, disable all interaction of this component | | value | string | null | initial phone number | | style | object | null | custom styles to be applied if supplied | | flagStyle | object | null | custom styles for flag image eg. {{width: 50, height: 30, borderWidth:0}} | | textStyle | object | null | custom styles for phone number text input eg. {{fontSize: 14}} | | textProps | object | null | properties for phone number text input eg. {{placeholder: 'Telephone number'}} | | textComponent | function | TextField | the input component to use | | offset | int | 10 | distance between flag and phone number | | pickerButtonColor | string | '#007AFF' | set button color of country picker | | pickerBackgroundColor | string | 'white' | set background color of country picker | | pickerItemStyle | object | null | custom styles for text in country picker eg. {{fontSize: 14}} | | cancelText | string | 'Cancel' | cancel word | | confirmText | string | 'Confirm' | confirm word | | buttonTextStyle | object | null | custom styles for country picker button | | onChangePhoneNumber | function(number) | null | function to be invoked when phone number is changed | | onSelectCountry | function(iso2) | null | function to be invoked when country picker is selected | | onPressFlag | function() | null | function to be invoked when press on flag image | | countriesList | array | null | custom countries list |

Functions:

| Function Name | Return Type | Parameters | Description | |---------------|----------|-------------|----------------------------------------------------------------| | isValidNumber | boolean | none | return true if current phone number is valid | | getNumberType | string | none | return true type of current phone number | | getValue | string | none | return current phone number | | getFlag | object | iso2:string | return flag image | | getAllCountries | object | none | return country object in country picker | | getPickerData | object | nont | return country object with flag image | | focus | void | none | focus the phone input | | selectCountry | void | iso2:string | set phone input to specific country | | getCountryCode | string | none | return country dial code of current phone number | | getISOCode | string | none | return country iso code of current phone number |