This repository was archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
142 lines (131 loc) · 4.8 KB
/
App.js
File metadata and controls
142 lines (131 loc) · 4.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
import React, {useState, useEffect, createContext} from 'react';
import { Platform } from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {GoogleSignin} from '@react-native-google-signin/google-signin';
import BuildConfig from 'react-native-build-config';
import HomeScreen from './screens/HomeScreen';
import PlayAudioScreen from './screens/PlayAudioScreen';
import BookOptionsScreen from './screens/BookOptionsScreen';
import LoginScreen from './screens/LoginScreen';
import SettingsScreen from './screens/SettingsScreen';
import PDFUploadScreen from './screens/PDFUploadScreen';
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
import {faUserCircle} from '@fortawesome/free-solid-svg-icons';
import {faHome} from '@fortawesome/free-solid-svg-icons';
import {faPlusCircle} from '@fortawesome/free-solid-svg-icons';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
export const UserContext = createContext();
function HomeScreenStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="HomeScreen"
component={HomeScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="PlayAudioScreen"
component={PlayAudioScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="BookOptionsScreen"
component={BookOptionsScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
);
}
export default function App() {
const [signedIn, setSignedIn] = useState(false);
const [userInfo, setUserInfo] = useState();
const [notifications, setNotifications] = useState();
useEffect(() => {
GoogleSignin.configure({
scopes: ['email'], // what API you want to access on behalf of the user, default is email and profile
offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
...Platform.select({ // client ID of type WEB for your server (needed to verify user ID and offline access)
ios: {
webClientId: BuildConfig.webClientId, // for iOS
},
android: {
webClientId: BuildConfig.CLIENT_SERVER_ID, // for Android
}
})
});
// Function to check is user is currently signed in and gets current user information if so
const isSignedIn = async () => {
const isSignedIn = await GoogleSignin.isSignedIn();
if (isSignedIn) {
const currentUser = await GoogleSignin.getCurrentUser();
setSignedIn(true);
setUserInfo(currentUser);
}
};
isSignedIn();
}, []);
return (
<UserContext.Provider
value={{signedIn, setSignedIn, userInfo, setUserInfo, notifications, setNotifications}}>
<NavigationContainer>
{!signedIn ? (
<Stack.Navigator>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
) : (
<Tab.Navigator
initialRouteName="HomeScreen"
activeColor="#f0edf6"
inactiveColor="#3e2465"
barStyle={{backgroundColor: '#992999'}}
screenOptions={({route}) => ({
tabBarIcon: ({focused, color, size}) => {
let iconName;
if (route.name === 'Home') {
iconName = faHome;
} else if (route.name === 'PDFUpload') {
iconName = faPlusCircle;
} else if (route.name === 'Settings') {
iconName = faUserCircle;
}
return (
<FontAwesomeIcon icon={iconName} size={25} color={'black'} />
);
},
tabBarActiveTintColor: 'black',
tabBarActiveBackgroundColor: 'lightgrey',
tabBarInactiveTintColor: 'gray',
tabBarShowLabel: false,
tabBarHideOnKeyboard: true,
})}>
<Tab.Screen
name="Home"
component={HomeScreenStack}
options={{headerShown: false}}
/>
<Tab.Screen
name="PDFUpload"
component={PDFUploadScreen}
options={{headerShown: false}}
/>
<Tab.Screen
name="Settings"
component={SettingsScreen}
options={{
headerShown: false,
tabBarBadge: (notifications?.notifications?.length) ? notifications.notifications.length : null
}}
/>
</Tab.Navigator>
)}
</NavigationContainer>
</UserContext.Provider>
);
}