react-native-contacts 7.0.5 → 7.0.7
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/.tool-versions +1 -0
- package/README.md +19 -16
- package/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java +1 -1
- package/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java +11 -3
- package/index.d.ts +10 -4
- package/package.json +1 -1
- package/foo.js +0 -1
package/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nodejs 19.2.0
|
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,7 +61,7 @@ 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
66
|
### react native version 60 and above
|
|
64
67
|
|
|
@@ -1218,7 +1218,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1218
1218
|
*/
|
|
1219
1219
|
private String isPermissionGranted() {
|
|
1220
1220
|
// return -1 for denied and 1
|
|
1221
|
-
int res = getReactApplicationContext().
|
|
1221
|
+
int res = getReactApplicationContext().checkSelfPermission(PERMISSION_READ_CONTACTS);
|
|
1222
1222
|
return (res == PackageManager.PERMISSION_GRANTED) ? PERMISSION_AUTHORIZED : PERMISSION_DENIED;
|
|
1223
1223
|
}
|
|
1224
1224
|
|
|
@@ -185,7 +185,7 @@ public class ContactsProvider {
|
|
|
185
185
|
/*contact id not found */
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
if (rawCursor
|
|
188
|
+
if (cursorMoveToNext(rawCursor)) {
|
|
189
189
|
int columnIndex;
|
|
190
190
|
columnIndex = rawCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
|
|
191
191
|
if (columnIndex == -1) {
|
|
@@ -304,12 +304,20 @@ public class ContactsProvider {
|
|
|
304
304
|
return contacts;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
private Boolean cursorMoveToNext(Cursor cursor) {
|
|
308
|
+
try {
|
|
309
|
+
return cursor.moveToNext();
|
|
310
|
+
} catch(RuntimeException error) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
307
315
|
@NonNull
|
|
308
316
|
private Map<String, Contact> loadContactsFrom(Cursor cursor) {
|
|
309
317
|
|
|
310
318
|
Map<String, Contact> map = new LinkedHashMap<>();
|
|
311
319
|
|
|
312
|
-
while (cursor != null && cursor
|
|
320
|
+
while (cursor != null && cursorMoveToNext(cursor)) {
|
|
313
321
|
|
|
314
322
|
int columnIndexContactId = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
|
|
315
323
|
int columnIndexId = cursor.getColumnIndex(ContactsContract.Data._ID);
|
|
@@ -573,7 +581,7 @@ public class ContactsProvider {
|
|
|
573
581
|
null
|
|
574
582
|
);
|
|
575
583
|
try {
|
|
576
|
-
if (cursor != null && cursor
|
|
584
|
+
if (cursor != null && cursorMoveToNext(cursor)) {
|
|
577
585
|
String rawPhotoURI = cursor.getString(cursor.getColumnIndex(Contactables.PHOTO_URI));
|
|
578
586
|
if (!TextUtils.isEmpty(rawPhotoURI)) {
|
|
579
587
|
return rawPhotoURI;
|
package/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export function getAll(): Promise<Contact[]>;
|
|
2
2
|
export function getAllWithoutPhotos(): Promise<Contact[]>;
|
|
3
|
-
export function getContactById(contactId: string): Promise<Contact>;
|
|
3
|
+
export function getContactById(contactId: string): Promise<Contact | null>;
|
|
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;
|
|
@@ -71,6 +76,7 @@ export interface Contact {
|
|
|
71
76
|
suffix: string;
|
|
72
77
|
department: string;
|
|
73
78
|
birthday: Birthday;
|
|
74
|
-
imAddresses: InstantMessageAddress[]
|
|
79
|
+
imAddresses: InstantMessageAddress[];
|
|
80
|
+
urlAddresses: UrlAddress[];
|
|
75
81
|
note: string;
|
|
76
82
|
}
|
package/package.json
CHANGED
package/foo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('hello')
|