# react-native-phone-number

> Request Phone Number on Android

Latest version **1.0.1** (published 2023-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-phone-number
pnpm add react-native-phone-number
yarn add react-native-phone-number
bun add react-native-phone-number
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-06-25 |
| First published | 2022-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Pranav.Chatly |
| Maintainers | witpranav |
| Keywords | react-native, react-native-phone-number, react, native, android, phone, number |

## Links

- npm: https://www.npmjs.com/package/react-native-phone-number
- Repository: https://github.com/witPranav/react-native-phone-number
- Homepage: https://github.com/witPranav/react-native-phone-number#readme
- Issues: https://github.com/witPranav/react-native-phone-number/issues
- npm.io page: https://npm.io/package/react-native-phone-number

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-06-25
- 1.0.0 — 2022-05-21

## README

# react-native-phone-number

## Getting started

`$ npm install react-native-phone-number --save`

## Note
- This module works only for android at the moment.

## How it works
-- This module provides 2 methods both of which provide a native overlay from which the user can select a phone number.
- requestPhoneNumber: which uses [GetPhoneNumberHintIntentRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetPhoneNumberHintIntentRequest) and [Identity](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/Identity) APIs to provide the phone number.
&
- hintRequestPhoneNumber: which uses [GoogleApiClient](https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient) and [HintRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/credentials/HintRequest) which are deprecated APIs to provide the phone number.

## Usage
- Goto app level build.gradle in android/app/build.gradle and add the following dependency.
```groovy
dependencies {
    ...
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation "com.google.android.gms:play-services-auth:20.2.0" // Add this line
    }
```

```javascript
import PhoneNumber from 'react-native-phone-number';
    
// Get status constants from the module
const {STATUS_CANCELLED, STATUS_ERROR, STATUS_SUCCESS} = PhoneNumber.getConstants();

// Recommended method for obtaining the phone number
PhoneNumber.requestPhoneNumber((res) => {
      if(res.status === STATUS_SUCCESS){
        //process res.data
      }else if(res.status === STATUS_CANCELLED){
        //handle cancel res.data
      }else if(res.status === STATUS_ERROR){
        //handle error res.data
      }
});

// Deprecated method for obtaining the phone number
PhoneNumber.hintRequestPhoneNumber((res) => {
      if(res.status === STATUS_SUCCESS){
        //process res.data
      }else if(res.status === STATUS_CANCELLED){
        //handle cancel res.data
      }else if(res.status === STATUS_ERROR){
        //handle error res.data
      }
});
```

---
_Source: https://npm.io/package/react-native-phone-number · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
