-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
117 lines (109 loc) · 3.07 KB
/
App.tsx
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useEffect } from "react";
import type { Node } from "react";
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
PermissionsAndroid,
} from "react-native";
import Navigation from "./src/navigation";
import Colors from "./src/constants/Colors";
import { Amplify, Hub } from "aws-amplify";
import config from "./src/aws-exports";
import { SafeAreaProvider } from "react-native-safe-area-context";
import * as RootNavigation from "./src/navigation/RootNavigation";
Amplify.configure(config);
const App: () => Node = () => {
const isDarkMode = useColorScheme() === "dark";
const backgroundStyle = {
backgroundColor: isDarkMode
? Colors.default.black.primary
: Colors.default.white.light,
};
const getAndroidPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Permission d'accès à votre localisation précise",
message:
"Nous désirons accéder à votre localisation précise afin de vous proposer les Uber cars les plus proches.",
buttonNegative: "Demander ultérieurement",
buttonNeutral: "Annuler",
buttonPositive: "Ok",
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Do smthg
console.log("Fine Geolocation enabled!");
} else {
// Close App
console.warn("Fine Geolocation denied!");
}
} catch (e) {
console.warn(
"\n\nPermissionsAndroid.request ACCESS_FINE_LOCATION\n",
e,
);
}
};
useEffect(() => {
getAndroidPermission();
}, []);
useEffect(() => {
const fetchAuthUser = async () => {
Hub.listen("auth", (data) => {
console.log("Hub.listen data", data);
switch (data.payload.event) {
case "signIn":
console.log("user signed in");
RootNavigation.navigate("Root", { screen: "Home" });
break;
case "signUp":
console.log("user signed up");
RootNavigation.navigate("Login");
break;
case "signOut":
console.log("user signed out");
RootNavigation.navigate("Login");
break;
case "signIn_failure":
console.log("user sign in failed", data);
break;
case "configured":
console.log("the Auth module is configured");
}
});
};
fetchAuthUser();
}, []);
return (
<SafeAreaProvider
initialMetrics={{
frame: { x: 0, y: 0, width: 0, height: 0 },
insets: { top: 0, left: 0, right: 0, bottom: 0 },
}}
>
{/*
<StatusBar
barStyle={isDarkMode ? "light-content" : "dark-content"}
transparent={true}
backgroundColor={"transparent"}
/>
*/}
<Navigation />
</SafeAreaProvider>
);
};
export default App;