This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
81 lines (78 loc) · 3.38 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
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import Constants from "expo-constants";
import React from "react";
import { Provider as PaperProvider } from "react-native-paper";
import { ApiContextProvider } from "./api";
import { AuthContextProvider } from "./auth/AuthContext";
import { DashboardScreen } from "./dashboard/DashboardScreen";
import {
MainNavigatorParamList,
MainScreenName,
TrackEmissionsNavigatorParamList,
TrackEmissionsScreenName,
} from "./navigation";
import { theme } from "./theme";
import { OverviewScreen } from "./track-emissions/OverviewScreen";
import { TrackEmissionsScreen } from "./track-emissions/TrackEmissionsScreen";
import { TransportDetailsScreen } from "./track-emissions/TransportDetailsScreen";
import { toHeaderTitle } from "./track-emissions/TransportMode";
import { TransportModeScreen } from "./track-emissions/TransportModeScreen";
const TrackEmissionsNavigator = createNativeStackNavigator<TrackEmissionsNavigatorParamList>();
const MainNavigator = createBottomTabNavigator<MainNavigatorParamList>();
function Emissions() {
return (
<TrackEmissionsNavigator.Navigator initialRouteName={TrackEmissionsScreenName.OVERVIEW}>
<TrackEmissionsNavigator.Screen name={TrackEmissionsScreenName.OVERVIEW} component={OverviewScreen} />
<TrackEmissionsNavigator.Screen
name={TrackEmissionsScreenName.TRACK_EMISSIONS}
component={TrackEmissionsScreen}
options={{ animation: "slide_from_right" }}
/>
<TrackEmissionsNavigator.Screen
name={TrackEmissionsScreenName.TRANSPORT_MODE}
component={TransportModeScreen}
options={{ animation: "slide_from_right" }}
/>
<TrackEmissionsNavigator.Screen
name={TrackEmissionsScreenName.TRANSPORT_DETAILS}
component={TransportDetailsScreen}
options={({ route }) => ({ title: toHeaderTitle(route.params.mode), animation: "slide_from_right" })}
/>
</TrackEmissionsNavigator.Navigator>
);
}
export default function App() {
return (
<PaperProvider theme={theme}>
<AuthContextProvider>
<ApiContextProvider baseURL={Constants.manifest?.extra?.apiBaseUrl}>
<NavigationContainer>
<MainNavigator.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ color }) => {
let iconName: "home" | "view-list" | undefined;
if (route.name === MainScreenName.DASHBOARD) {
iconName = "home";
} else if (route.name === MainScreenName.EMISSIONS) {
iconName = "view-list";
}
return <MaterialCommunityIcons name={iconName} size={24} color={color} />;
},
})}
>
<MainNavigator.Screen name={MainScreenName.DASHBOARD} component={DashboardScreen} />
<MainNavigator.Screen
name={MainScreenName.EMISSIONS}
component={Emissions}
options={{ headerShown: false }}
/>
</MainNavigator.Navigator>
</NavigationContainer>
</ApiContextProvider>
</AuthContextProvider>
</PaperProvider>
);
}