1 | <div align="center">
|
2 | <img src="./gif/Phone_Number_Input_Layout_1.gif" height="400" title="Anurag Garg" alt="Anurag Garg" style="box-shadow: 0 20px 30px 3px rgba(9, 9, 16, 0.2);">
|
3 | <img src="./gif/Phone_Number_Input_Layout_2.gif" height="400" title="Anurag Garg" alt="Anurag Garg" style="box-shadow: 0 20px 30px 3px rgba(9, 9, 16, 0.2);">
|
4 | </div>
|
5 |
|
6 | <br>
|
7 |
|
8 | <h1 align="center">React Native Phone Number Input
|
9 | </h1>
|
10 |
|
11 | <p align="center">Performance oriented React Native Phone Number Input with typings and proper validation for any country.
|
12 | </p>
|
13 |
|
14 | <h6 align="center">Made with ❤️ by developer for developers</h6>
|
15 |
|
16 | <br>
|
17 | <p align="center">
|
18 | <img src="http://img.shields.io/travis/badges/badgerbadgerbadger.svg?style=flat-square" alt="build"/>
|
19 | <img src="https://img.shields.io/github/issues/garganurag893/react-native-phone-number-input" alt="build"/>
|
20 | <img src="https://img.shields.io/github/issues-pr/garganurag893/react-native-phone-number-input" alt="build"/>
|
21 | <img src="http://img.shields.io/:license-mit-blue.svg?style=flat-square" alt="build"/>
|
22 | </p>
|
23 |
|
24 | ## Want to show your love?
|
25 | <p>Click on 🌟 button.</p>
|
26 |
|
27 |
|
28 | ## Table of Contents
|
29 |
|
30 | - [Table of Contents](#table-of-contents)
|
31 | - [Installation](#installation)
|
32 | - [Features](#features)
|
33 | - [Usage](#usage)
|
34 | - [Props](#props)
|
35 | - [Methods](#methods)
|
36 | - [FAQ](#faq)
|
37 | - [Is it supported and tested both on android and iOS?](#is-it-supported-and-tested-both-on-android-and-ios)
|
38 | - [NSURLResponse allHeaderFields: unrecognized selector sent to instance XX crash?](#nsurlresponse-allheaderfields-unrecognized-selector-sent-to-instance-xx-crash)
|
39 | - [Contributing](#contributing)
|
40 | - [Step 1](#step-1)
|
41 | - [Step 2](#step-2)
|
42 | - [Step 3](#step-3)
|
43 | - [Support](#support)
|
44 | - [License](#license)
|
45 | - [Hire](#hire)
|
46 |
|
47 | ## Installation
|
48 |
|
49 | ```bash
|
50 | $ yarn add react-native-phone-number-input
|
51 | ```
|
52 |
|
53 | OR
|
54 |
|
55 | ```bash
|
56 | $ npm i react-native-phone-number-input --save
|
57 | ```
|
58 |
|
59 | ## Features
|
60 |
|
61 | - :iphone: Works with iOS and Android, Cross-platform :100:
|
62 | - :crossed_flags: Built-in country picker (uses [react-native-country-picker-modal][react-native-country-picker-modal])
|
63 | - :wrench: Completely customizable UI!
|
64 | - :heavy_check_mark: Proper validation (uses [google-libphonenumber](https://github.com/google/libphonenumber))
|
65 |
|
66 | ## Usage
|
67 |
|
68 | For more complete example open [App.tsx](https://github.com/garganurag893/react-native-phone-number-input/blob/master/example/App.tsx)
|
69 |
|
70 | ```tsx
|
71 | import React, { useState, useRef } from "react";
|
72 | import {
|
73 | SafeAreaView,
|
74 | StyleSheet,
|
75 | View,
|
76 | StatusBar,
|
77 | TouchableOpacity,
|
78 | Text,
|
79 | } from "react-native";
|
80 | import PhoneInput from "react-native-phone-number-input";
|
81 | import { Colors } from "react-native/Libraries/NewAppScreen";
|
82 |
|
83 | const App: React.FC = () => {
|
84 | const [value, setValue] = useState("");
|
85 | const [formattedValue, setFormattedValue] = useState("");
|
86 | const [valid, setValid] = useState(false);
|
87 | const [showMessage, setShowMessage] = useState(false);
|
88 | const phoneInput = useRef<PhoneInput>(null);
|
89 | return (
|
90 | <>
|
91 | <StatusBar barStyle="dark-content" />
|
92 | <View style={styles.container}>
|
93 | <SafeAreaView style={styles.wrapper}>
|
94 | {showMessage && (
|
95 | <View style={styles.message}>
|
96 | <Text>Value : {value}</Text>
|
97 | <Text>Formatted Value : {formattedValue}</Text>
|
98 | <Text>Valid : {valid ? "true" : "false"}</Text>
|
99 | </View>
|
100 | )}
|
101 | <PhoneInput
|
102 | ref={phoneInput}
|
103 | defaultValue={value}
|
104 | defaultCode="DM"
|
105 | layout="first"
|
106 | onChangeText={(text) => {
|
107 | setValue(text);
|
108 | }}
|
109 | onChangeFormattedText={(text) => {
|
110 | setFormattedValue(text);
|
111 | }}
|
112 | withDarkTheme
|
113 | withShadow
|
114 | autoFocus
|
115 | />
|
116 | <TouchableOpacity
|
117 | style={styles.button}
|
118 | onPress={() => {
|
119 | const checkValid = phoneInput.current?.isValidNumber(value);
|
120 | setShowMessage(true);
|
121 | setValid(checkValid ? checkValid : false);
|
122 | }}
|
123 | >
|
124 | <Text>Check</Text>
|
125 | </TouchableOpacity>
|
126 | </SafeAreaView>
|
127 | </View>
|
128 | </>
|
129 | );
|
130 | };
|
131 |
|
132 | export default App;
|
133 | ```
|
134 |
|
135 | ## Props
|
136 |
|
137 | - `defaultCode?`: [CountryCode](https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/types.ts#L252)
|
138 | - `withDarkTheme?`: boolean
|
139 | - `withShadow?`: boolean
|
140 | - `autoFocus?`: boolean
|
141 | - `defaultValue?`: string
|
142 | - `value?`: string
|
143 | - `disabled?`: boolean
|
144 | - `disableArrowIcon?`: boolean
|
145 | - `placeholder?`: string;
|
146 | - `onChangeCountry?`: (country: Country) => void;
|
147 | - `onChangeText?`: (text: string) => void;
|
148 | - `onChangeFormattedText?`: (text: string) => void;
|
149 | - `containerStyle?`: `StyleProp<ViewStyle>`;
|
150 | - `textContainerStyle?`: `StyleProp<ViewStyle>`;
|
151 | - `renderDropdownImage?`: `JSX.Element`;
|
152 | - `textInputProps?`: [TextInputProps](https://reactnative.dev/docs/textinput);
|
153 | - `textInputStyle?`: `StyleProp<TextStyle>`;
|
154 | - `codeTextStyle?`: `StyleProp<TextStyle>`;
|
155 | - `flagButtonStyle?`: `StyleProp<ViewStyle>`;
|
156 | - `countryPickerButtonStyle` : `StyleProp<ViewStyle>`;
|
157 | - `layout?`: "first" | "second";
|
158 | - `filterProps?`: CountryFilterProps;
|
159 | - `countryPickerProps?`: any;
|
160 |
|
161 | ## Methods
|
162 |
|
163 | - `getCountryCode`: () => [CountryCode](https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/types.ts#L252)
|
164 | - `getCallingCode`: () => string | undefined
|
165 | - `getNumberAfterPossiblyEliminatingZero`: () => {number: string , formattedNumber: string };
|
166 | - `isValidNumber`: (number: string) => boolean
|
167 |
|
168 | ## FAQ
|
169 |
|
170 | ### Is it supported and tested both on android and iOS?
|
171 |
|
172 | YES
|
173 |
|
174 | ### NSURLResponse allHeaderFields: unrecognized selector sent to instance XX crash?
|
175 |
|
176 | Upgrade `versions['Flipper'] ||= '~> 0.37.0'` in podfile.
|
177 |
|
178 | ## Contributing
|
179 |
|
180 | > To get started...
|
181 |
|
182 | ### Step 1
|
183 |
|
184 | - **Option 1**
|
185 |
|
186 | - 🍴 Fork this repo!
|
187 |
|
188 | - **Option 2**
|
189 | - 👯 Clone this repo to your local machine using `https://github.com/garganurag893/react-native-phone-number-input`
|
190 |
|
191 | ### Step 2
|
192 |
|
193 | - **HACK AWAY!** 🔨🔨🔨
|
194 |
|
195 | ### Step 3
|
196 |
|
197 | - 🔃 Create a new pull request using <a href="https://github.com/garganurag893/react-native-phone-number-input" target="_blank">`https://github.com/garganurag893/react-native-phone-number-input`</a>.
|
198 |
|
199 | ## Support
|
200 |
|
201 | Reach out to me at one of the following places!
|
202 |
|
203 | - Twitter at <a href="https://twitter.com/AnuragG94634191" target="_blank">https://twitter.com/AnuragG94634191</a>
|
204 | - Medium at <a href="https://medium.com/@garganurag893" target="_blank">https://medium.com/@garganurag893</a>
|
205 | - Instagram at <a href="https://www.instagram.com/the_only_anurag/" target="_blank">https://www.instagram.com/the_only_anurag/</a>
|
206 | - Email at garganurag893@gmail.com
|
207 |
|
208 | ## License
|
209 |
|
210 | [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org)
|
211 |
|
212 | - **[MIT license](http://opensource.org/licenses/mit-license.php)**
|
213 |
|
214 | ## Hire
|
215 |
|
216 | Looking for a React/React-Native Freelance Expert? Email at garganurag893@gmail.com
|
217 |
|
218 | [react-native-country-picker-modal]: https://github.com/xcarpentier/react-native-country-picker-modal
|