Skip to content

Commit

Permalink
contacts android done
Browse files Browse the repository at this point in the history
  • Loading branch information
nishStoryDigital committed Sep 20, 2021
1 parent 72492e4 commit fd3d5b4
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions app/screens/permissions/contacts/ContactsList.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ const ContactsList = () => {
const [contacts, setContacts] = React.useState([]);

const getContactList = async () => {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
title: 'Contacts',
message: 'This app would like to view your contacts.',
buttonPositive: 'Accept',
},
)
.then(Contacts.getAll())
.then(contacts => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
title: 'Contacts',
message: 'This app would like to view your contacts.',
buttonPositive: 'Accept',
buttonNegative: 'Cancel',
},
);
console.log('granted: ', granted);

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
const contacts = Contacts.getAll();
console.log(contacts[0]);

let newContacts = [];
contacts.map(contact => {
newContacts.push({
Expand All @@ -50,10 +56,15 @@ const ContactsList = () => {
: -1,
);
setContacts(newContacts);
});
} else {
console.log('Contacts permission denied');
}
} catch (err) {
console.warn(err);
}
};

// getContactList();
getContactList();

if (!contacts) {
return (
Expand Down

0 comments on commit fd3d5b4

Please sign in to comment.