mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 05:27:57 -05:00
* [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>
45 lines
965 B
TypeScript
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);
|
|
}
|
|
}
|