Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-contact

silentnerd70MIT0.0.8TypeScript support: included

This is simple wrapper that return an array of contacts which can be handled by the developer for their specific use.

react, react-native, contacts, address book, people, select contact

readme

react-native-contact

This is simple wrapper that return an array of contacts which can be handled by the developer for their specific use.

Installation

yarn add react-native-contact

For React Native => 0.59 only:

react-native link react-native-contact

Make sure your manifest files includes permission to read contacts

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

API

Methods

selectContact(): Promise<Contact | null>;
selectContactPhone(): Promise<ContactPhoneSelection | null>;
selectContactEmail(): Promise<ContactEmailSelection | null>;
selectContactPostalAddress(): Promise<ContactPostalAddressSelection | null>;

These methods all will return an array. Which in turn can be handled by the developer for their specific need.

Types

interface PhoneEntry {
    number: string,
    type: string
}

interface EmailEntry {
    address: string,
    type: string
}

interface AddressEntry {
    formattedAddress: string, // android only
    type: string, // android only
    street: string,
    city: string,
    state: string,
    postalCode: string,
    isoCountryCode: string
}

interface Contact {
    name: string,
    phones: PhoneEntry[],
    emails: EmailEntry[],
    postalAddresses: AddressEntry[]
}

interface ContactPhoneSelection {
    contact: Contact,
    selectedPhone: PhoneEntry
}

interface ContactEmailSelection {
    contact: Contact,
    selectedEmail: EmailEntry
}

interface ContactPostalAddressSelection {
    contact: Contact,
    selectedAddress: AddressEntry
}

Example


import { selectContactPhone } from 'react-native-contact';

function getPhoneNumber() {
    return selectContactPhone()
        .then(selection => {
            if (!selection) {
                return null;
            }

            console.log('Contact phone numbers: '+selection);
        });  
}

changelog

1.2.1

  • Add Podfile for RN 0.60+

1.2.0

  • Add recordId to contacts [#5]

1.1.1

  • Updated typescript typings with postal address fields

1.1.0

  • Returning postal address data with contact's now
  • New API call to select a contact's postal address
  • Returning separate name elements for givenName, familyName, and middleName

1.0.0

  • Initial release