Skip to content

Commit

Permalink
location & contacts done
Browse files Browse the repository at this point in the history
  • Loading branch information
nishStoryDigital committed Sep 20, 2021
1 parent fd3d5b4 commit dc22dd5
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 47 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package="com.nish.reactnativelibs">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:name=".MainApplication"
Expand Down
4 changes: 2 additions & 2 deletions app/navigation/DrawerNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Settings from '_Screens/settings/Settings';
import Razorpay from '_Screens/razorpay/Razorpay';
import Permissions from '_Screens/permissions';
import ContactsList from '_Screens/permissions/contacts/ContactsList';
// import Location from '_Screens/permissions/location/Location';
import Location from '_Screens/permissions/location/Location';

const Drawer = createDrawerNavigator();

Expand All @@ -25,7 +25,7 @@ const NavDrawer = () => {
{/* Permission Related Screens */}
<Drawer.Screen name="Permissions" component={Permissions} />
<Drawer.Screen name="ContactsList" component={ContactsList} />
{/* <Drawer.Screen name="Location" component={Location} /> */}
<Drawer.Screen name="Location" component={Location} />
</Drawer.Navigator>
);
};
Expand Down
7 changes: 4 additions & 3 deletions app/screens/permissions/contacts/ContactsList.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import Header from '_Shared/Header';
import ContactItem from './ContactItem';

/* Read the Guide - https://www.npmjs.com/package/react-native-contacts */

const ContactsList = () => {
/* Make sure to add relevant permissions in AndroidManifest.xml" */

const { t } = useTranslation('common');
const [contacts, setContacts] = React.useState([]);

Expand All @@ -29,11 +32,9 @@ const ContactsList = () => {
buttonNegative: 'Cancel',
},
);
console.log('granted: ', granted);

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

let newContacts = [];
contacts.map(contact => {
Expand Down
80 changes: 80 additions & 0 deletions app/screens/permissions/location/Location.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import { PermissionsAndroid, Button, View } from 'react-native';
import Geolocation from 'react-native-geolocation-service';

import { ThemedContainer, ThemedBody, ThemedText } from '_Shared/Comps.themed';
import Header from '_Shared/Header';

/*
Read about the lib setup here -
https://github.com/Agontuk/react-native-geolocation-service/blob/HEAD/docs/setup.md
*/

const Location = () => {
/* Make sure to add relevant permissions in AndroidManifest.xml" */
const [status, setStatus] = React.useState('');
const [coords, setCoords] = React.useState({});

const getLocationPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location',
message: 'This app would like to get your location.',
buttonPositive: 'Accept',
buttonNegative: 'Cancel',
},
);

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
getCurrentPosition();
} else {
console.log('Location permission denied');
}
} catch (err) {
console.warn(err);
}
};

const getCurrentPosition = () => {
Geolocation.getCurrentPosition(
position => {
setCoords(position);
},
error => {
setStatus(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
);
};

getLocationPermission();

return (
<ThemedContainer>
<Header title="Location" />
<ThemedBody>
<ThemedText>
Device permission granted to use location. Current status -{' '}
{status}
</ThemedText>
<Button
title="Get position"
onPress={() => getCurrentPosition()}
/>
{coords?.coords?.latitude && (
<View>
<ThemedText>Current Position is - </ThemedText>
<ThemedText>
( {coords.coords.latitude},{' '}
{coords.coords.longitude} )
</ThemedText>
</View>
)}
</ThemedBody>
</ThemedContainer>
);
};

export default Location;
38 changes: 0 additions & 38 deletions app/screens/permissions/location/Location.js

This file was deleted.

6 changes: 3 additions & 3 deletions app/screens/razorpay/Razorpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const Razorpay = () => {
currency: 'INR',
key: Config.RAZORPAY_KEY,
amount: 100,
name: 'Jon',
name: 'Tester',
prefill: {
email: 'test@razorpay.com',
email: 'nishkohli96@gmail.com',
contact: '9814110843',
name: 'Razorpay Software',
name: 'Nishant',
},
theme: { color: '#007ABA' },
};
Expand Down
2 changes: 1 addition & 1 deletion app/store/lang.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { makeAutoObservable, configure } from 'mobx';
import AsyncStorage from '@react-native-async-storage/async-storage';

export class LangStore {
langName = 'hi';
langName = 'en';

constructor() {
configure({
Expand Down

0 comments on commit dc22dd5

Please sign in to comment.