-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
132 lines (119 loc) · 3.59 KB
/
App.tsx
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
import React, { useEffect } from "react";
import MaterialIcon from "react-native-vector-icons/MaterialIcons";
import { View, StyleSheet, Image, Text, Alert } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import Config from "react-native-config";
import SplashScreen from "react-native-splash-screen";
import PostsScreen from "./src/PostsScreen";
import FilesScreen from "./src/FilesScreen";
// import FormsScreen from "./src/FormsScreen";
import CalendarScreen from "./src/CalendarScreen";
import CongressScreen from "./src/CongressScreen";
const MSU_LOGO = require("./assets/logo-white.png");
import messaging from "@react-native-firebase/messaging";
import {requestUserPermission} from "./notifications.js";
const icons: { [key: string]: any } = {
Posts: "chat",
Resources: "info",
Forms: "note",
Calendar: "event",
Congress: "people",
};
const styles = StyleSheet.create({
label: {
fontSize: 10,
},
headerImage: {
height: 38,
resizeMode: "contain",
},
errorRoot: {
...StyleSheet.absoluteFillObject,
justifyContent: "center",
alignItems: "center",
},
errorTitle: {
textAlign: "center",
fontWeight: "bold",
},
});
const TabNav = createBottomTabNavigator();
const TabNavScreen = () => (
<TabNav.Navigator
initialRouteName="Posts"
tabBarOptions={{
labelStyle: styles.label,
}}
screenOptions={({ route }: any) => ({
tabBarIcon: ({ color, size }: any) => (
<MaterialIcon name={icons[route.name]} color={color} size={size} />
),
})}
>
<TabNav.Screen name="Posts" component={PostsScreen} />
<TabNav.Screen name="Resources" component={FilesScreen} />
{/* <TabNav.Screen name="Forms" component={FormsScreen} /> */}
<TabNav.Screen name="Calendar" component={CalendarScreen} />
<TabNav.Screen name="Congress" component={CongressScreen} />
</TabNav.Navigator>
);
const RootStack = createStackNavigator();
const RootStackScreen = () => (
<RootStack.Navigator
screenOptions={{
headerTitleAlign: "center",
}}
>
<RootStack.Screen
name="Home"
component={TabNavScreen}
options={{
headerTitle: () => (
<Image source={MSU_LOGO} style={styles.headerImage} />
),
}}
/>
</RootStack.Navigator>
);
// List of environment variables that must be set in .env.
// If they are not set, the App prints and displays an error.
const CONFIG_VARS = ["SERVER_URL"];
const App = () => {
// Ensure all env variables are set. If any is not, print missing variables.
if (!CONFIG_VARS.every(x => x in Config)) {
const missing = CONFIG_VARS.filter(x => !(x in Config));
console.error("Environment variables missing from .env:");
console.error(`${missing}`);
return (
<View style={styles.errorRoot}>
<Text style={styles.errorTitle}>
Environment variables are missing from .env:
</Text>
{missing.map(x => (
<Text>{x}</Text>
))}
</View>
);
}
useEffect(() => {
requestUserPermission();
SplashScreen.hide();
messaging()
.getToken()
.then(token => console.log(token));
}, []);
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert("A new FCM message arrived!", JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
return (
<NavigationContainer>
<RootStackScreen />
</NavigationContainer>
);
};
export default App;