react-native-contacts 7.0.4 → 7.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -21,22 +21,25 @@ On android you must request permissions beforehand
|
|
|
21
21
|
import { PermissionsAndroid } from 'react-native';
|
|
22
22
|
import Contacts from 'react-native-contacts';
|
|
23
23
|
|
|
24
|
-
PermissionsAndroid.request(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_CONTACTS, {
|
|
25
|
+
title: 'Contacts',
|
|
26
|
+
message: 'This app would like to view your contacts.',
|
|
27
|
+
buttonPositive: 'Please accept bare mortal',
|
|
28
|
+
})
|
|
29
|
+
.then((res) => {
|
|
30
|
+
console.log('Permission: ', res);
|
|
31
|
+
Contacts.getAll()
|
|
32
|
+
.then((contacts) => {
|
|
33
|
+
// work with contacts
|
|
34
|
+
console.log(contacts);
|
|
35
|
+
})
|
|
36
|
+
.catch((e) => {
|
|
37
|
+
console.log(e);
|
|
38
|
+
});
|
|
36
39
|
})
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
console.error('Permission error: ', error);
|
|
42
|
+
});
|
|
40
43
|
```
|
|
41
44
|
|
|
42
45
|
## Installation
|
|
@@ -58,9 +61,9 @@ If you were previously using manually linking follow these steps to upgrade
|
|
|
58
61
|
```
|
|
59
62
|
react-native unlink react-native-contacts
|
|
60
63
|
npm install latest version of react-native-contacts
|
|
61
|
-
|
|
64
|
+
You're good to go!
|
|
62
65
|
```
|
|
63
|
-
### react native version 60 and above
|
|
66
|
+
### react native version 60 and above
|
|
64
67
|
|
|
65
68
|
If you are using react native version 0.60 or above you do not have to link this library.
|
|
66
69
|
|
|
@@ -230,11 +233,21 @@ If you'd like to read/write the contact's notes, call the `iosEnableNotesUsage(t
|
|
|
230
233
|
imAddresses: [
|
|
231
234
|
{ username: '0123456789', service: 'ICQ'},
|
|
232
235
|
{ username: 'johndoe123', service: 'Facebook'}
|
|
233
|
-
]
|
|
236
|
+
],
|
|
237
|
+
isStarred: false,
|
|
234
238
|
}
|
|
235
239
|
```
|
|
236
|
-
|
|
240
|
+
|
|
241
|
+
### Android only
|
|
242
|
+
|
|
237
243
|
* on Android versions below 8 the entire display name is passed in the `givenName` field. `middleName` and `familyName` will be `""`.
|
|
244
|
+
* isStarred field
|
|
245
|
+
* writePhotoToPath() - writes the contact photo to a given path
|
|
246
|
+
|
|
247
|
+
## iOS only
|
|
248
|
+
|
|
249
|
+
checkPermission(): Promise - checks permission to access Contacts
|
|
250
|
+
requestPermission(): Promise - request permission to access Contacts
|
|
238
251
|
|
|
239
252
|
## Adding Contacts
|
|
240
253
|
Currently all fields from the contact record except for thumbnailPath are supported for writing
|
|
@@ -110,10 +110,15 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
110
110
|
ContentResolver cr = context.getContentResolver();
|
|
111
111
|
|
|
112
112
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
113
|
-
|
|
113
|
+
try {
|
|
114
|
+
Integer contacts = contactsProvider.getContactsCount();
|
|
115
|
+
promise.resolve(contacts);
|
|
116
|
+
} catch (Exception e) {
|
|
117
|
+
promise.reject(e);
|
|
118
|
+
}
|
|
114
119
|
|
|
115
|
-
promise.resolve(contacts);
|
|
116
120
|
return null;
|
|
121
|
+
|
|
117
122
|
}
|
|
118
123
|
};
|
|
119
124
|
myAsyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
@@ -37,6 +37,7 @@ public class ContactsProvider {
|
|
|
37
37
|
add(ContactsContract.Data.CONTACT_ID);
|
|
38
38
|
add(ContactsContract.Data.RAW_CONTACT_ID);
|
|
39
39
|
add(ContactsContract.Data.LOOKUP_KEY);
|
|
40
|
+
add(ContactsContract.Data.STARRED);
|
|
40
41
|
add(ContactsContract.Contacts.Data.MIMETYPE);
|
|
41
42
|
add(ContactsContract.Profile.DISPLAY_NAME);
|
|
42
43
|
add(Contactables.PHOTO_URI);
|
|
@@ -184,7 +185,7 @@ public class ContactsProvider {
|
|
|
184
185
|
/*contact id not found */
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
if (rawCursor
|
|
188
|
+
if (cursorMoveToNext(rawCursor)) {
|
|
188
189
|
int columnIndex;
|
|
189
190
|
columnIndex = rawCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
|
|
190
191
|
if (columnIndex == -1) {
|
|
@@ -303,12 +304,20 @@ public class ContactsProvider {
|
|
|
303
304
|
return contacts;
|
|
304
305
|
}
|
|
305
306
|
|
|
307
|
+
private Boolean cursorMoveToNext(Cursor cursor) {
|
|
308
|
+
try {
|
|
309
|
+
return cursor.moveToNext();
|
|
310
|
+
} catch(RuntimeException error) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
306
315
|
@NonNull
|
|
307
316
|
private Map<String, Contact> loadContactsFrom(Cursor cursor) {
|
|
308
317
|
|
|
309
318
|
Map<String, Contact> map = new LinkedHashMap<>();
|
|
310
319
|
|
|
311
|
-
while (cursor != null && cursor
|
|
320
|
+
while (cursor != null && cursorMoveToNext(cursor)) {
|
|
312
321
|
|
|
313
322
|
int columnIndexContactId = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
|
|
314
323
|
int columnIndexId = cursor.getColumnIndex(ContactsContract.Data._ID);
|
|
@@ -344,10 +353,13 @@ public class ContactsProvider {
|
|
|
344
353
|
Contact contact = map.get(contactId);
|
|
345
354
|
String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
|
|
346
355
|
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
356
|
+
int starred = cursor.getInt(cursor.getColumnIndex(ContactsContract.Data.STARRED));
|
|
357
|
+
Boolean isStarred = starred == 1;
|
|
347
358
|
contact.rawContactId = rawContactId;
|
|
348
359
|
if (!TextUtils.isEmpty(name) && TextUtils.isEmpty(contact.displayName)) {
|
|
349
360
|
contact.displayName = name;
|
|
350
361
|
}
|
|
362
|
+
contact.isStarred = isStarred;
|
|
351
363
|
|
|
352
364
|
if (TextUtils.isEmpty(contact.photoUri)) {
|
|
353
365
|
String rawPhotoURI = cursor.getString(cursor.getColumnIndex(Contactables.PHOTO_URI));
|
|
@@ -569,7 +581,7 @@ public class ContactsProvider {
|
|
|
569
581
|
null
|
|
570
582
|
);
|
|
571
583
|
try {
|
|
572
|
-
if (cursor != null && cursor
|
|
584
|
+
if (cursor != null && cursorMoveToNext(cursor)) {
|
|
573
585
|
String rawPhotoURI = cursor.getString(cursor.getColumnIndex(Contactables.PHOTO_URI));
|
|
574
586
|
if (!TextUtils.isEmpty(rawPhotoURI)) {
|
|
575
587
|
return rawPhotoURI;
|
|
@@ -599,6 +611,7 @@ public class ContactsProvider {
|
|
|
599
611
|
private List<Item> urls = new ArrayList<>();
|
|
600
612
|
private List<Item> instantMessengers = new ArrayList<>();
|
|
601
613
|
private boolean hasPhoto = false;
|
|
614
|
+
private boolean isStarred = false;
|
|
602
615
|
private String photoUri;
|
|
603
616
|
private List<Item> emails = new ArrayList<>();
|
|
604
617
|
private List<Item> phones = new ArrayList<>();
|
|
@@ -626,6 +639,7 @@ public class ContactsProvider {
|
|
|
626
639
|
contact.putString("note", note);
|
|
627
640
|
contact.putBoolean("hasThumbnail", this.hasPhoto);
|
|
628
641
|
contact.putString("thumbnailPath", photoUri == null ? "" : photoUri);
|
|
642
|
+
contact.putBoolean("isStarred", this.isStarred);
|
|
629
643
|
|
|
630
644
|
WritableArray phoneNumbers = Arguments.createArray();
|
|
631
645
|
for (Item item : phones) {
|
package/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ export function getAllWithoutPhotos(): Promise<Contact[]>;
|
|
|
3
3
|
export function getContactById(contactId: string): Promise<Contact>;
|
|
4
4
|
export function getCount(): Promise<number>;
|
|
5
5
|
export function getPhotoForId(contactId: string): Promise<string>;
|
|
6
|
-
export function addContact(contact: Contact): Promise<
|
|
6
|
+
export function addContact(contact: Partial<Contact>): Promise<Contact>;
|
|
7
7
|
export function openContactForm(contact: Partial<Contact>): Promise<Contact>;
|
|
8
8
|
export function openExistingContact(contact: Contact): Promise<Contact>;
|
|
9
9
|
export function viewExistingContact(contact: { recordID: string }): Promise<Contact | void>
|
|
10
10
|
export function editExistingContact(contact: Contact): Promise<Contact>;
|
|
11
|
-
export function updateContact(contact: Contact): Promise<void>;
|
|
11
|
+
export function updateContact(contact: Partial<Contact> & {recordID: string}): Promise<void>;
|
|
12
12
|
export function deleteContact(contact: Contact): Promise<void>;
|
|
13
13
|
export function getContactsMatchingString(str: string): Promise<Contact[]>;
|
|
14
14
|
export function getContactsByPhoneNumber(phoneNumber: string): Promise<Contact[]>;
|
|
@@ -52,6 +52,11 @@ export interface Birthday {
|
|
|
52
52
|
year: number;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export interface UrlAddress {
|
|
56
|
+
url: string;
|
|
57
|
+
label: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
export interface Contact {
|
|
56
61
|
recordID: string;
|
|
57
62
|
backTitle: string;
|
|
@@ -65,11 +70,13 @@ export interface Contact {
|
|
|
65
70
|
phoneNumbers: PhoneNumber[];
|
|
66
71
|
hasThumbnail: boolean;
|
|
67
72
|
thumbnailPath: string;
|
|
73
|
+
isStarred: boolean;
|
|
68
74
|
postalAddresses: PostalAddress[];
|
|
69
75
|
prefix: string;
|
|
70
76
|
suffix: string;
|
|
71
77
|
department: string;
|
|
72
78
|
birthday: Birthday;
|
|
73
|
-
imAddresses: InstantMessageAddress[]
|
|
79
|
+
imAddresses: InstantMessageAddress[];
|
|
80
|
+
urlAddresses: UrlAddress[];
|
|
74
81
|
note: string;
|
|
75
82
|
}
|