Files
inji-wallet/shared/location.ts
Srikanth Kola 8fb0312221 [INJIMOB-785]: add location permission rational (#1376)
* [INJIMOB-785]: add location permission rational

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-785]: Change naming convention of events and create a component for rational

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-785]: refactor location service rational

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

---------

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>
2024-04-22 12:34:34 +05:30

45 lines
965 B
TypeScript

import RNLocation from 'react-native-location';
// Initialize RNLocation
RNLocation.configure({
distanceFilter: 5.0, // Example configuration, adjust as needed
});
export function checkLocationPermissionStatus(
onEnabled: () => void,
onDisabled: () => void,
) {
RNLocation.checkPermission({
android: {
detail: 'fine',
},
})
.then(granted => {
if (granted) {
return onEnabled();
} else {
return onDisabled();
}
})
.catch(err => console.error('Error getting location:', err));
}
export async function requestLocationPermission(
onEnabled: () => void,
onDisabled: () => void,
) {
try {
const granted = await RNLocation.requestPermission({
android: {
detail: 'fine',
},
});
if (granted) {
return onEnabled();
} else {
return onDisabled();
}
} catch (error) {
console.error('Error while requesting location permission', error);
}
}