-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
252 lines (234 loc) · 7.89 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import React, { Suspense, useEffect, useContext, useState } from "react";
import { Text, LogBox, Dimensions } from "react-native";
import { NavigationContainer, getFocusedRouteNameFromRoute } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { BottomTabBar, createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import HomeScreen from "./Screens/HomeScreen";
import { useFonts } from "expo-font";
import WelcomeScreenNew from "./Screens/WelcomeScreen";
import BookInfo from "./Screens/BookInfo.js";
import PDFExample from "./Screens/BookReader";
import LiveTranslation from "./Screens/LiveTranslation.js";
import Settings from "./Screens/Settings";
import * as firebase from "firebase/app";
import { firebaseConfig } from "./firebase.js";
import Splash from "./Screens/Splash.js";
import BookAddInfo from "./Screens/BookAddInfo.js";
import { AdminPage } from "./Screens/AdminPage.js";
import CustomTranslation from "./Screens/CustomTranslation.js";
import { Library } from "./Screens/Library.js";
import { Ionicons } from "@expo/vector-icons";
import { AddPDF } from "./Screens/AddPDF.js";
import { NativeBaseProvider } from "native-base";
import { Icon } from "native-base";
import AuthContextProvider, { AuthContext } from "./context/authContext";
import { Storage } from "expo-storage";
async function getStorage(key, array = false) {
var val = JSON.parse(await Storage.getItem({ key: key }));
if (array === true) val = Array.from(val);
return val;
}
LogBox.ignoreAllLogs();
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
const HomeScreenStack = createNativeStackNavigator();
function HomeNavigator() {
return (
<HomeScreenStack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: "#10b981",
},
headerTintColor: "#fff", //Set Header text color
headerTitleStyle: {
fontWeight: "bold", //Set Header text style
},
}}
>
<HomeScreenStack.Screen
options={{ headerShown: false, orientation: 'portrait' }}
name="Home Screen" component={HomeScreen} />
<HomeScreenStack.Screen
options={{ headerShown: false, orientation: 'portrait' }}
name="Add Book: Info" component={BookAddInfo} />
<HomeScreenStack.Screen
options={{ orientation: 'portrait' }}
name="Live Translation"
component={LiveTranslation}
/>
<HomeScreenStack.Screen
name="Custom Translation"
options={{ headerShown: false, orientation: 'portrait' }}
component={CustomTranslation}
/>
<HomeScreenStack.Screen options={{ orientation: 'portrait' }} name="Book Info" component={BookInfo} />
<HomeScreenStack.Screen name="Book Reader" component={PDFExample} />
</HomeScreenStack.Navigator>
);
}
const LibraryScreenStack = createNativeStackNavigator();
function LibraryNavigator() {
return (
<LibraryScreenStack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: "#10b981",
},
headerTintColor: "#fff", //Set Header text color
headerTitleStyle: {
fontWeight: "bold", //Set Header text style
},
}}
>
<LibraryScreenStack.Screen
name="Library Home Page"
options={{ headerShown: false, orientation: 'portrait' }}
component={Library}
/>
<LibraryScreenStack.Screen name="Book Info" component={BookInfo} options={{ orientation: 'portrait' }} />
<LibraryScreenStack.Screen
name="Book Reader"
component={PDFExample}
/>
</LibraryScreenStack.Navigator>
);
}
const AdminScreenStack = createNativeStackNavigator();
function AdminNavigator() {
return (
<AdminScreenStack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: "#10b981",
},
headerTintColor: "#fff", //Set Header text color
headerTitleStyle: {
fontWeight: "bold", //Set Header text style
},
}}
>
<AdminScreenStack.Screen name="Admin Page" component={AdminPage} options={{ orientation: 'portrait' }} />
<AdminScreenStack.Screen name="Add Book: Info" component={BookAddInfo} options={{ orientation: 'portrait' }} />
<AdminScreenStack.Screen name="Add PDF" component={AddPDF} options={{ orientation: 'portrait' }} />
</AdminScreenStack.Navigator>
);
}
//style for the tabBarContainer
const tabBar = {
borderRadius: 100,
position: "absolute",
zIndex: 3,
height: Dimensions.get("window").height * 0.1,
backgroundColor: "#0ea5e9",
marginBottom: 18,
shadowOpacity: 0.6,
opacity: 0.7,
};
const Tab = createBottomTabNavigator();
function TabNavigator(props) {
const [isAdmin, setIsAdmin] = useState(false);
// Would need to be tested with an actual admin account
useEffect(() => {
const checkIsAdmin = async () => {
const isAdmin = await getStorage("isAdmin");
setIsAdmin(isAdmin);
};
checkIsAdmin();
}, [isAdmin]);
return (
<Tab.Navigator
screenOptions={({ route }) => ({
headerShown: false,
tabBarHideOnKeyboard: true,
tabBarStyle: tabBar,
headerStyle: {
backgroundColor: "#047857",
},
tabBarIconStyle: {
paddingTop: 0,
paddingBottom: 0,
},
tabBarLabelStyle: {
paddingTop: 0,
},
headerTintColor: "#fff", //Set Header text color
headerTitleStyle: {
fontWeight: "bold", //Set Header text style
},
tabBarInactiveTintColor: "#ffff",
tabBarActiveTintColor: "#4ade80",
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === "Home") iconName = "home";
else if (route.name === "Library") iconName = "library";
else if (route.name === "Settings") iconName = "cog";
else if (route.name === "Admin") iconName = "lock-closed";
return (
<Ionicons
name={iconName}
size={size}
color={focused ? "#4ade80" : "#fff"}
/>
);
},
})}
>
<Tab.Screen name="Home" component={HomeNavigator} />
<Tab.Screen
options={({ route }) => ({
tabBarStyle: ((route) => {
const routeName = getFocusedRouteNameFromRoute(route) ?? ""
console.log(routeName)
if (routeName === 'Book Reader') {
return { display: "none" }
}
return tabBar
})(route),
})}
name="Library"
component={LibraryNavigator}
/>
{isAdmin && <Tab.Screen name="Admin" component={AdminNavigator} />}
<Tab.Screen
name="Settings"
component={Settings}
options={{ headerShown: false }}
/>
</Tab.Navigator>
);
}
const SignupStack = createNativeStackNavigator();
export default function App() {
let [fontsLoaded] = useFonts({
"Roboto-Black": require("./assets/fonts/Roboto-Black.ttf"),
"Roboto-BlackItalic": require("./assets/fonts/Roboto-BlackItalic.ttf"),
"Roboto-Bold": require("./assets/fonts/Roboto-Bold.ttf"),
});
if (!fontsLoaded) {
return <Text> Loading ... </Text>;
}
return (
<Suspense fallback="Loading...">
<AuthContextProvider>
<NativeBaseProvider>
<NavigationContainer>
<SignupStack.Navigator
screenOptions={{
headerShown: false,
}}
>
<SignupStack.Screen name="Splash" component={Splash} />
<SignupStack.Screen
name="Welcome Screen"
component={WelcomeScreenNew}
options={{ headerShown: false }}
/>
<SignupStack.Screen name="Tabs" component={TabNavigator} />
</SignupStack.Navigator>
</NavigationContainer>
</NativeBaseProvider>
</AuthContextProvider>
</Suspense>
);
}