How to use expo-contacts - 10 common examples

To help you get started, we’ve selected a few expo-contacts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo / apps / native-component-list / src / screens / Contacts / ContactDetailScreen.tsx View on Github external
_setNewPhoto = async (uri: string) => {
    // console.log(this.id, this.state.contact, uri);
    try {
      await Contacts.updateContactAsync({
        [Contacts.Fields.ID]: this.id,
        [Contacts.Fields.Image]: uri,
      } as any);
    } catch ({ message }) {
      // tslint:disable-next-line no-console
      console.error(message);
    }

    this.loadAsync();
  }
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactDetailScreen.tsx View on Github external
label: item.label || item.localizedService,
              };
              break;
            case Contacts.Fields.UrlAddresses:
              transform = {
                value: item.url,
                onPress: () => {
                  const webUrl = item.url.indexOf('://') === -1 ? 'http://' + item.url : item.url;

                  // tslint:disable-next-line no-console
                  console.log('open', item.url, webUrl);
                  Linking.openURL(webUrl);
                },
              };
              break;
            case Contacts.Fields.Dates:
              transform = {
                value: ContactUtils.parseDate(item).toDateString(),
              };
              break;
            case Contacts.Fields.Emails:
              transform = {
                value: item.email,
                onPress: () => Linking.openURL(`mailto:${item.email}`),
              };
              break;
            case Contacts.Fields.Addresses:
              {
                const address = ContactUtils.parseAddress(item);
                const targetUriAdress = encodeURI(address);
                transform = {
                  value: address,
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactUtils.ts View on Github external
export async function removeAllChildrenFromGroupWithNameAsync(groupName: string) {
  try {
    const groupId = await ensureGroupAsync(groupName);

    const { data: contacts } = await Contacts.getContactsAsync({ groupId });
    await Promise.all(
      contacts.map(contact => Contacts.removeContactFromGroupAsync(contact.id, groupId!))
    );
  } catch ({ message }) {
    // tslint:disable-next-line no-console
    console.error(message);
  }
}
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactDetailScreen.tsx View on Github external
loadAsync = async () => {
    if (!this.state.permission) {
      return;
    }
    this.setState({ refreshing: true });
    const contact = await Contacts.getContactByIdAsync(this.id);

    this.setState({
      contact,
      refreshing: false,
    });
    // tslint:disable-next-line no-console
    console.log(contact);
  }
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactDetailScreen.tsx View on Github external
deleteAsync = async () => {
    try {
      await Contacts.removeContactAsync(this.id);
      this.props.navigation.goBack();
    } catch ({ message }) {
      // tslint:disable-next-line no-console
      console.error(message);
    }
  }
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactUtils.ts View on Github external
export async function deleteGroupWithNameAsync(groupName: string) {
  try {
    const group = await getGroupWithNameAsync(groupName);
    if (group) {
      Contacts.removeGroupAsync(group.id!);
    }
  } catch ({ message }) {
    // tslint:disable-next-line no-console
    console.error(message);
  }
}
github expo / expo / apps / native-component-list / src / screens / Contacts / ContactDetailScreen.tsx View on Github external
_setNewPhoto = async (uri: string) => {
    // console.log(this.id, this.state.contact, uri);
    try {
      await Contacts.updateContactAsync({
        [Contacts.Fields.ID]: this.id,
        [Contacts.Fields.Image]: uri,
      } as any);
    } catch ({ message }) {
      // tslint:disable-next-line no-console
      console.error(message);
    }

    this.loadAsync();
  }
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
const enabled = state.settings.contacts.importEnabled
  if (!enabled || !perm) {
    if (enabled && !perm) {
      logger.info('contact import enabled but no contact permissions')
    }
    if (enabled === null) {
      logger.info("haven't loaded contact import enabled")
    }
    return
  }

  // feature enabled and permission granted
  let contacts: Contacts.ContactResponse
  try {
    contacts = await Contacts.getContactsAsync({
      fields: [Contacts.Fields.Name, Contacts.Fields.PhoneNumbers, Contacts.Fields.Emails],
    })
  } catch (e) {
    logger.error(`error loading contacts: ${e.message}`)
    return SettingsGen.createSetContactImportedCount({error: e.message})
  }
  let defaultCountryCode: string = ''
  try {
    defaultCountryCode = await NativeModules.Utils.getDefaultCountryCode()
    if (__DEV__ && !defaultCountryCode) {
      // behavior of parsing can be unexpectedly different with no country code.
      // iOS sim + android emu don't supply country codes, so use this one.
      defaultCountryCode = 'us'
    }
  } catch (e) {
    logger.warn(`Error loading default country code: ${e.message}`)
  }
github keybase / client / shared / teams / invite-by-contact / fetch-contacts.native.tsx View on Github external
const fetchContacts = async (regionFromState: string): Promise<[Array, string]> => {
  const contacts = await Contacts.getContactsAsync({
    fields: [
      Contacts.Fields.Name,
      Contacts.Fields.PhoneNumbers,
      Contacts.Fields.Emails,
      Contacts.Fields.ImageAvailable,
      Contacts.Fields.Image,
    ],
  })

  let region = ''
  if (regionFromState) {
    logger.debug(`Got region from state: ${regionFromState}, no need to call NativeModules.`)
    region = regionFromState
  } else {
    try {
      let defaultCountryCode = await NativeModules.Utils.getDefaultCountryCode()
      if (__DEV__ && !defaultCountryCode) {
        // behavior of parsing can be unexpectedly different with no country code.
github celo-org / celo-monorepo / packages / dappkit / src / index.ts View on Github external
export async function fetchContacts(
  kit: ContractKit
): Promise<{ rawContacts: ContactsById; phoneNumbersByAddress: PhoneNumberMappingEntryByAddress }> {
  const contacts = await getContactsAsync({
    fields: [Fields.PhoneNumbers, Fields.Image],
  })

  const filteredContacts = contacts.data.filter((contact) => {
    return (
      contact.phoneNumbers && find(contact.phoneNumbers, (p) => isValidPhoneNumber(p) !== undefined)
    )
  })

  const rawContacts = fromPairs(filteredContacts.map((contact) => [contact.id, contact]))

  // @ts-ignore
  const phoneNumbersToContacts = createPhoneNumberToContactMapping(filteredContacts)

  const phoneNumbersByAddress = await lookupPhoneNumbersOnAttestations(kit, phoneNumbersToContacts)