react-native-contacts icon indicating copy to clipboard operation
react-native-contacts copied to clipboard

isStarred is not working

Open theshilovs opened this issue 1 year ago • 5 comments

Thanks for the library!

Android, "react": "18.2.0", "react-native-contacts": "^7.0.8",

  const newContactPhone = () => {
    Contacts.addContact({
      familyName: 'test',
      givenName: 'test',
      isStarred: true,
    }).then(contact => {
      console.log(contact, 'CONTACTPHONE');
    });
  };

LOG {"company": null, "department": null, "displayName": "test test", "emailAddresses": [], "familyName": "test", "givenName": "test", "hasThumbnail": false, "imAddresses": [], "isStarred": false, "jobTitle": null, "middleName": "", "note": null, "phoneNumbers": [], "postalAddresses": [], "prefix": null, "rawContactId": "4765", "recordID": "4766", "suffix": null, "thumbnailPath": "", "urlAddresses": []} CONTACTPHONE

How is it?

theshilovs avatar Dec 09 '23 19:12 theshilovs

looks like the starred option is never unpacked on android

import android.provider.ContactsContract.ContactOptionsColumns

https://developer.android.com/reference/android/provider/ContactsContract.ContactOptionsColumns#STARRED

    @ReactMethod
    public void addContact(ReadableMap contact, Promise promise) {
        if (contact == null) {
            promise.reject("New contact cannot be null.");
            return;
        }
        String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null;
        String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null;
        String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null;
        String prefix = contact.hasKey("prefix") ? contact.getString("prefix") : null;
...

https://github.com/morenoh149/react-native-contacts/blob/0258847f17b116bf38a343f2ac339606f4c76f9c/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java#L602

morenoh149 avatar Dec 14 '23 02:12 morenoh149

Hello! I might have a similar issue to address here. I noticed that the isStarred property though present on the example contact record is not showing on the Contact interface provided by the library:

export interface Contact {
    recordID: string;
    backTitle: string;
    company: string|null;
    emailAddresses: EmailAddress[];
    displayName: string;
    familyName: string;
    givenName: string;
    middleName: string;
    jobTitle: string;
    phoneNumbers: PhoneNumber[];
    hasThumbnail: boolean;
    thumbnailPath: string;
    postalAddresses: PostalAddress[];
    prefix: string;
    suffix: string;
    department: string;
    birthday: Birthday;
    imAddresses: InstantMessageAddress[]
    note: string;
}

Is there a reason for this? Has this property been recently unsupported? Is it because this property is only supposed to be available on Android devices?

Thanks!

ayelenguini avatar Jan 08 '24 19:01 ayelenguini

@ayelenguini its just an oversight. When we first wrote the example we did not support typescript. Ts annotations were added later by another author. isStarred should be added to the ts definition but we should also check that they are properly set when creating a new contact.

morenoh149 avatar Jan 08 '24 20:01 morenoh149

@morenoh149 and what about when requesting the contact list itself? would this property be available on the return object? is it only available on android?

ayelenguini avatar Jan 08 '24 20:01 ayelenguini

@ayelenguini it's probably missing when requesting the contact list itself as well

morenoh149 avatar Jan 24 '24 19:01 morenoh149

This issue is stale, please provide more information about the status

github-actions[bot] avatar Mar 25 '24 00:03 github-actions[bot]