-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
143 lines (131 loc) · 3.8 KB
/
App.js
File metadata and controls
143 lines (131 loc) · 3.8 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useEffect, useState } from "react";
import { ApplicationProvider, IconRegistry } from "@ui-kitten/components";
import Context from "./Context/Context";
import * as eva from "@eva-design/eva";
import { EvaIconsPack } from "@ui-kitten/eva-icons";
import AsyncStorage from "@react-native-async-storage/async-storage";
import SplashScreen from "react-native-splash-screen";
import { createStackNavigator } from "@react-navigation/stack";
import { NavigationContainer, DefaultTheme } from "@react-navigation/native";
import Tabs from "./navigation/tabs";
// import {COLORS} from './constants';
import {
SafeAreaView,
StatusBar,
StyleSheet,
useColorScheme,
} from "react-native";
import Header from "./navigation/Header";
import { COLORS } from "./constants";
import Login from "./navigation/Login/LoginModal";
import { navigationRef } from "./navigation/RootNavigation";
import { InAppNotificationProvider } from "react-native-in-app-notification";
const Stack = createStackNavigator();
const App = () => {
const [userDetails, setUserDetails] = useState({});
const [visible, setVisible] = useState(false);
const [loggedIn, setLoggedIn] = useState(false);
// const getData = async () => {
// try {
// const jsonValue = await AsyncStorage.getItem("@storage_Key");
// return jsonValue != null ? JSON.parse(jsonValue) : null;
// } catch (e) {
// // error reading value
// }
// };
const isDarkMode = useColorScheme() === "dark";
const backgroundStyle = {
backgroundColor: COLORS.black,
};
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: COLORS.darkerBlack,
},
};
const userDataHandler = async () => {
try {
const value = await AsyncStorage.getItem("userData");
if (value !== null) {
// We have data!!
const userData = JSON.parse(value);
setUserDetails(userData);
setLoggedIn(true);
}
} catch (error) {
console.log("error");
}
};
useEffect(() => {
userDataHandler();
const loginHandler = () => {};
SplashScreen.hide();
if (userDetails) {
setVisible(true);
}
}, []);
return (
<InAppNotificationProvider>
<Context.Provider
value={{
userDetails: userDetails,
setUserDetails: (userData) => setUserDetails(userData),
setModalVisible: setVisible,
loggedIn: loggedIn,
setLoggedIn: (val) => {
if (val === false) {
AsyncStorage.clear();
}
setLoggedIn(val);
},
}}
>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={eva.dark}>
<SafeAreaView style={backgroundStyle}>
<StatusBar
barStyle={isDarkMode ? "light-content" : "light-content"}
/>
<Header />
{visible && <Login setVisible={(value) => setVisible(value)} />}
</SafeAreaView>
<NavigationContainer ref={navigationRef} theme={MyTheme}>
<Stack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName="Home"
>
<Stack.Screen name="Home" component={Tabs} />
</Stack.Navigator>
</NavigationContainer>
</ApplicationProvider>
</Context.Provider>
</InAppNotificationProvider>
);
};
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: "600",
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: "400",
},
highlight: {
fontWeight: "700",
},
});
export default App;