-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
170 lines (160 loc) · 6.78 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import * as React from "react";
import { useState, useEffect } from "react";
import { NavigationContainer, DefaultTheme } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createStackNavigator } from "@react-navigation/stack";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import AsyncStorage from "@react-native-async-storage/async-storage";
//context menu
import BookProvider from "./Pages/Context/book";
import Login from "./Login";
import Home from "./Pages/Home";
import Camera from "./Pages/Camera";
import Book from "./Pages/CreateBook";
import List from "./Pages/List/index";
import BookPage from "./Pages/BookPage";
import BookPageComments from "./Pages/BookPage/Components/Comments";
import BookLoan from "./Pages/BookPage/Components/Loan";
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
function MyTabs({ navigation }) {
const logout = async () => {
await AsyncStorage.setItem("@token", JSON.stringify(false));
};
return (
<>
<Tab.Navigator
shifting={true}
sceneAnimationEnabled={false}
screenOptions={{
tabBarActiveTintColor: "white",
tabBarInactiveTintColor: "gray",
headerStyle: {
backgroundColor: "#444",
},
headerTitleStyle: {
color: "white",
},
headerLeft: () => <MaterialCommunityIcons onPress={() => navigation.goBack()} style={{ marginTop: 5, marginLeft: 20 }} name="arrow-left" color="white" size={26} />,
tabBarStyle: {
paddingBottom: 6,
backgroundColor: "#333",
borderTopColor: "#444",
},
}}
>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="book" color="white" size={26} />,
// tabBarButton: () => null,
headerLeft: () => null,
}}
name="Lista de Livros"
component={List}
/>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="home" color="white" size={26} />,
showLabel: false,
headerLeft: () => null,
tabBarButton: () => null,
}}
name="Início"
component={Home}
/>
<Tab.Screen
options={{
tabBarLabel: "Cadastro de Livro",
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="barcode" color="white" size={26} />,
}}
name="Código de Barras"
component={Camera}
/>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="book" color="white" size={26} />,
tabBarButton: () => null,
}}
name="Cadastro de Livro"
component={Book}
/>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="book" color="white" size={26} />,
tabBarButton: () => null,
headerLeft: () => (
<MaterialCommunityIcons onPress={() => navigation.navigate("Lista de Livros")} style={{ marginTop: 5, marginLeft: 20 }} name="arrow-left" color="white" size={26} />
),
}}
name="Pagina do Livro"
component={BookPage}
/>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="book" color="white" size={26} />,
tabBarButton: () => null,
headerLeft: () => (
<MaterialCommunityIcons onPress={() => navigation.navigate("Pagina do Livro")} style={{ marginTop: 5, marginLeft: 20 }} name="arrow-left" color="white" size={26} />
),
}}
name="Comentários"
component={BookPageComments}
/>
<Tab.Screen
options={{
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="book" color="white" size={26} />,
tabBarButton: () => null,
headerLeft: () => (
<MaterialCommunityIcons onPress={() => navigation.navigate("Pagina do Livro")} style={{ marginTop: 5, marginLeft: 20 }} name="arrow-left" color="white" size={26} />
),
}}
name="Emprestimo"
component={BookLoan}
/>
<Tab.Screen
options={{
tabBarLabel: "Sair",
tabBarIcon: ({ color }) => <MaterialCommunityIcons name="logout" color="white" size={26} />,
tabBarStyle: { display: "none" },
headerLeft: () => null,
headerShown: false,
}}
name="logout"
component={Login}
listeners={({ navigation }) => ({
tabPress: e => logout(),
})}
/>
</Tab.Navigator>
</>
);
}
export default function App(navigation) {
const [logged, setLogged] = useState(false);
useEffect(async () => {
const token = await AsyncStorage.getItem("@token");
token === "false" ? setLogged(false) : setLogged(true);
}, []);
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: "#222",
background: "#222",
},
};
return (
<BookProvider>
<NavigationContainer theme={MyTheme}>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
{!logged && <Stack.Screen name="login" component={Login} />}
<Stack.Screen name="book" component={MyTabs} />
</Stack.Navigator>
</NavigationContainer>
</BookProvider>
);
}