-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathApp.js
65 lines (57 loc) · 1.72 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import 'react-native-gesture-handler';
import { enableScreens } from 'react-native-screens';
import React, { useEffect } from "react";
import { StatusBar, PermissionsAndroid, Platform } from "react-native";
import Geolocation from "@react-native-community/geolocation";
import RootNavigator from './src/Navigation/Root';
enableScreens();
// If you need to have geolocation API aligned with the browser (cross-platform apps),
// or want to support backward compatibility
navigator.geolocation = require('@react-native-community/geolocation');
const App = () => {
const requestLocationPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Uber App Location Permission",
message:
"Uber App needs access to your location " +
"so you can take awesome rides.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the location");
} else {
console.log("Location permission denied");
}
} catch (err) {
console.warn(err);
}
};
useEffect(() => {
if (Platform.OS === "android") {
requestLocationPermission();
} else {
// IOS
Geolocation.requestAuthorization();
}
}, []); // Empty array means it will run only on component mount
return (
<>
<StatusBar barStyle="dark-content" />
<RootNavigator />
</>
);
};
export default App;