-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
App.tsx
207 lines (192 loc) Β· 6.52 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
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
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NavigationContainer, useTheme } from "@react-navigation/native";
import { observer } from "mobx-react";
import React, { useContext, useRef } from "react";
import { StatusBar } from "react-native";
import { AppearanceProvider, useColorScheme } from "react-native-appearance";
import { enableScreens } from "react-native-screens";
import { createNativeStackNavigator } from "react-native-screens/native-stack";
import { ThemeProvider } from "styled-components/native";
import HeaderSettingsButton from "./src/components/HeaderSettingsButton";
import Tabbar from "./src/components/Tabbar";
import AppearanceSettings from "./src/screens/AppearanceSettings";
import AppIconSettings from "./src/screens/AppIconSettings";
import Calendar from "./src/screens/Calendar";
import Dashboard from "./src/screens/Dashboard";
import Details from "./src/screens/Details";
import Licenses from "./src/screens/Licenses";
import News from "./src/screens/News";
import NotificationsSettings from "./src/screens/NotificationsSettings";
import Search from "./src/screens/Search";
import Settings from "./src/screens/Settings";
import AppState from "./src/stores/AppState";
import { darkTheme, lightTheme } from "./src/theme";
import { Themes } from "./src/types";
import analytics from '@react-native-firebase/analytics';
enableScreens();
const Tab = createBottomTabNavigator();
const HomeNav = createNativeStackNavigator();
const CalendarNav = createNativeStackNavigator();
const NewsNav = createNativeStackNavigator();
const SearchNav = createNativeStackNavigator();
const SettingsNav = createNativeStackNavigator();
const HomeStack = () => {
return (
<HomeNav.Navigator>
<HomeNav.Screen
options={{
headerTranslucent: false,
headerHideShadow: true,
headerTitle: "",
headerStyle: { backgroundColor: "transparent" },
// headerRight: HeaderSettingsButton,
}}
name="Home"
component={Dashboard}
/>
<HomeNav.Screen name="Details" component={Details} options={{headerBackTitle: "Back"}} />
<HomeNav.Screen name="Settings" component={SettingsStack} />
</HomeNav.Navigator>
);
};
const SettingsStack = () => {
const { colors } = useTheme();
return (
<SettingsNav.Navigator>
<SettingsNav.Screen
name="Settings"
component={Settings}
options={{
headerLargeTitle: true,
headerHideShadow: true,
headerStyle: { backgroundColor: colors.background },
}}
/>
<SettingsNav.Screen
name="Notifications"
component={NotificationsSettings}
/>
<SettingsNav.Screen name="Appearance" component={AppearanceSettings} />
<SettingsNav.Screen name="Icon" component={AppIconSettings} />
<SettingsNav.Screen
name="Licenses"
options={{
headerLargeTitle: true,
headerHideShadow: true,
headerStyle: { backgroundColor: colors.background },
}}
component={Licenses}
/>
</SettingsNav.Navigator>
);
};
const CalendarStack = () => {
const { colors } = useTheme();
return (
<CalendarNav.Navigator>
<CalendarNav.Screen
options={{
headerLargeTitle: false,
headerHideShadow: true,
headerStyle: { backgroundColor: colors.background },
}}
name="Calendar"
component={Calendar}
/>
<CalendarNav.Screen name="Details" component={Details} />
</CalendarNav.Navigator>
);
};
const NewsStack = () => {
const { colors } = useTheme();
return (
<NewsNav.Navigator>
<NewsNav.Screen
options={{
headerLargeTitle: true,
headerHideShadow: true,
headerStyle: { backgroundColor: colors.background },
}}
name="News"
component={News}
/>
</NewsNav.Navigator>
);
};
const SearchStack = () => {
const { colors } = useTheme();
return (
<SearchNav.Navigator>
<SearchNav.Screen
options={{
headerLargeTitle: true,
headerHideShadow: true,
headerStyle: { backgroundColor: colors.background },
}}
name="Search"
component={Search}
/>
<SearchNav.Screen name="Details" component={Details} />
</SearchNav.Navigator>
);
};
const App = observer(() => {
const scheme = useColorScheme();
const appStateStore = useContext(AppState);
const navigationRef = useRef();
const routeNameRef = useRef();
let theme;
let statusBarStyle;
if (appStateStore.theme === Themes.automatic) {
if (scheme === "dark") {
theme = darkTheme;
statusBarStyle = "light-content";
} else {
theme = lightTheme;
statusBarStyle = "dark-content";
}
} else if (appStateStore.theme === Themes.light) {
theme = lightTheme;
statusBarStyle = "dark-content";
} else if (appStateStore.theme === Themes.dark) {
theme = darkTheme;
statusBarStyle = "light-content";
}
return (
<AppearanceProvider>
<ThemeProvider theme={theme}>
<NavigationContainer
theme={theme}
ref={navigationRef}
onReady={() =>
(routeNameRef.current = navigationRef.current.getCurrentRoute().name)
}
onStateChange={async () => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.current.getCurrentRoute().name;
if (previousRouteName !== currentRouteName) {
// The line below uses the expo-firebase-analytics tracker
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
// Change this line to use another Mobile analytics SDK
await analytics().logScreenView({
screen_name: currentRouteName,
screen_class: currentRouteName,
});
}
// Save the current route name for later comparison
routeNameRef.current = currentRouteName;
}}>
<StatusBar barStyle={statusBarStyle} />
<Tab.Navigator tabBar={Tabbar}>
<Tab.Screen name="Home" component={HomeStack} />
<Tab.Screen name="Calendar" component={CalendarStack} />
<Tab.Screen name="News" component={NewsStack} />
<Tab.Screen name="Search" component={SearchStack} />
<Tab.Screen name="Settings" component={SettingsStack} />
</Tab.Navigator>
</NavigationContainer>
</ThemeProvider>
</AppearanceProvider>
);
});
export default App;