forked from leehsintaiwan/OwlSendUserApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
68 lines (62 loc) · 1.79 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
66
67
68
import AsyncStorage from "@react-native-async-storage/async-storage";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import HomeScreen from "./app/screens/HomeScreen";
import RegisterScreen from "./app/screens/RegisterScreen";
export default function App() {
const Stack = createNativeStackNavigator();
const [userProfile, setUserProfile] = useState(null);
const getUserProfile = async () => {
// Get user profile from device storage.
// AsyncStorage.clear(); // Uncomment to clear user profile
try {
const user = JSON.parse(await AsyncStorage.getItem("profile"));
if (user) {
setUserProfile(user.profile);
}
} catch (e) {
console.log(e);
}
};
const Home = ({ navigation, route }) => {
return (
<HomeScreen
navigation={navigation}
route={route}
userProfile={userProfile}
/>
);
};
const Register = ({ navigation, route }) => {
return (
<RegisterScreen
navigation={navigation}
route={route}
userProfile={userProfile}
setUserProfile={setUserProfile}
/>
);
};
useEffect(() => {
getUserProfile();
}, []);
return (
<NavigationContainer>
<StatusBar style="dark" />
<Stack.Navigator initialRouteName="Register">
<Stack.Screen
name="Home"
component={Home}
options={{ headerShown: false, gestureEnabled: false }}
/>
<Stack.Screen
name="Register"
component={Register}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}