0.1.2 • Published 1 year ago

react-native-contact-pick v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-contact-pick

react-native-contact-pick is a simple and easy-to-use library that provides a way to access the device's contacts and allows users to select one or more contacts from their address book.

Installation

npm install react-native-contact-pick

Make sure your manifest files includes permission to read contacts

<uses-permission android:name="android.permission.READ_CONTACTS" />

Usage

Make sure you ask the READ_CONTACTS permission on android.

import { pickContact } from 'react-native-contact-pick';

// ...

const onPress = async () => {
  try {
    const granted =
      Platform.OS === 'android'
        ? (await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.READ_CONTACTS
          )) === PermissionsAndroid.RESULTS.GRANTED
        : true;
    if (granted) {
      const res = await pickContact();
      // do some stuff
    }
  } catch (error) {
    if (error.code !== ERROR_CODES.ERR_CODE_CANCELED) {
      // error
    }
  }
};

Request Object

PropertyTypeDescription
isPhoneNumberDigitalbooleanConvert phones number to digital.false : 123-43-56-78true: 123435678

Contact Result Object Type

interface PickContactResult {
  fullName: string;
  phoneNumbers:
    | {
        type: string;
        number: string;
      }[]
    | null; // contact doesn't have phone numbers
  emails:
    | {
        type: string;
        email: string;
      }[]
    | null; // contact doesn't have emails
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago