Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainNavigator.tsx 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import { createStackNavigator } from '@react-navigation/stack';
  21. import i18n from 'i18n-js';
  22. import SettingsScreen from '../screens/Other/Settings/SettingsScreen';
  23. import AboutScreen from '../screens/About/AboutScreen';
  24. import AboutDependenciesScreen from '../screens/About/AboutDependenciesScreen';
  25. import DebugScreen from '../screens/About/DebugScreen';
  26. import TabNavigator from './TabNavigator';
  27. import GameMainScreen from '../screens/Game/screens/GameMainScreen';
  28. import VoteScreen from '../screens/Amicale/VoteScreen';
  29. import LoginScreen from '../screens/Amicale/LoginScreen';
  30. import SelfMenuScreen from '../screens/Services/SelfMenuScreen';
  31. import ProximoMainScreen from '../screens/Services/Proximo/ProximoMainScreen';
  32. import ProximoListScreen from '../screens/Services/Proximo/ProximoListScreen';
  33. import ProximoAboutScreen from '../screens/Services/Proximo/ProximoAboutScreen';
  34. import ProfileScreen from '../screens/Amicale/ProfileScreen';
  35. import ClubListScreen from '../screens/Amicale/Clubs/ClubListScreen';
  36. import ClubAboutScreen from '../screens/Amicale/Clubs/ClubAboutScreen';
  37. import ClubDisplayScreen from '../screens/Amicale/Clubs/ClubDisplayScreen';
  38. import BugReportScreen from '../screens/Other/FeedbackScreen';
  39. import WebsiteScreen from '../screens/Services/WebsiteScreen';
  40. import EquipmentScreen, {
  41. DeviceType,
  42. } from '../screens/Amicale/Equipment/EquipmentListScreen';
  43. import EquipmentLendScreen from '../screens/Amicale/Equipment/EquipmentRentScreen';
  44. import EquipmentConfirmScreen from '../screens/Amicale/Equipment/EquipmentConfirmScreen';
  45. import DashboardEditScreen from '../screens/Other/Settings/DashboardEditScreen';
  46. import GameStartScreen from '../screens/Game/screens/GameStartScreen';
  47. import ImageGalleryScreen from '../screens/Media/ImageGalleryScreen';
  48. import { usePreferences } from '../context/preferencesContext';
  49. import { getPreferenceBool, PreferenceKeys } from '../utils/asyncStorage';
  50. import IntroScreen from '../screens/Intro/IntroScreen';
  51. export enum MainRoutes {
  52. Main = 'main',
  53. Intro = 'Intro',
  54. Gallery = 'gallery',
  55. Settings = 'settings',
  56. DashboardEdit = 'dashboard-edit',
  57. About = 'about',
  58. Dependencies = 'dependencies',
  59. Debug = 'debug',
  60. GameStart = 'game',
  61. GameMain = 'game-main',
  62. Login = 'login',
  63. SelfMenu = 'self-menu',
  64. Proximo = 'proximo',
  65. ProximoList = 'proximo-list',
  66. ProximoAbout = 'proximo-about',
  67. Profile = 'profile',
  68. ClubList = 'club-list',
  69. ClubInformation = 'club-information',
  70. ClubAbout = 'club-about',
  71. EquipmentList = 'equipment',
  72. EquipmentRent = 'equipment-rent',
  73. EquipmentConfirm = 'equipment-confirm',
  74. Vote = 'vote',
  75. Feedback = 'feedback',
  76. Website = 'website',
  77. }
  78. type DefaultParams = { [key in MainRoutes]: object | undefined };
  79. export type FullParamsList = DefaultParams & {
  80. 'login': { nextScreen: string };
  81. 'equipment-confirm': {
  82. item?: DeviceType;
  83. dates: [string, string];
  84. };
  85. 'equipment-rent': { item?: DeviceType };
  86. 'gallery': { images: Array<{ url: string }> };
  87. [MainRoutes.ProximoList]: {
  88. shouldFocusSearchBar: boolean;
  89. category: number;
  90. };
  91. };
  92. // Don't know why but TS is complaining without this
  93. // See: https://stackoverflow.com/questions/63652687/interface-does-not-satisfy-the-constraint-recordstring-object-undefined
  94. export type MainStackParamsList = FullParamsList &
  95. Record<string, object | undefined>;
  96. const MainStack = createStackNavigator<MainStackParamsList>();
  97. function getIntroScreens() {
  98. return (
  99. <>
  100. <MainStack.Screen
  101. name={MainRoutes.Intro}
  102. component={IntroScreen}
  103. options={{
  104. headerShown: false,
  105. }}
  106. />
  107. </>
  108. );
  109. }
  110. function getRegularScreens(createTabNavigator: () => React.ReactElement) {
  111. return (
  112. <>
  113. <MainStack.Screen
  114. name={MainRoutes.Main}
  115. component={createTabNavigator}
  116. options={{
  117. headerShown: false,
  118. title: i18n.t('screens.home.title'),
  119. }}
  120. />
  121. <MainStack.Screen
  122. name={MainRoutes.Gallery}
  123. component={ImageGalleryScreen}
  124. options={{
  125. headerShown: false,
  126. }}
  127. />
  128. <MainStack.Screen
  129. name={MainRoutes.Settings}
  130. component={SettingsScreen}
  131. options={{
  132. title: i18n.t('screens.settings.title'),
  133. }}
  134. />
  135. <MainStack.Screen
  136. name={MainRoutes.DashboardEdit}
  137. component={DashboardEditScreen}
  138. options={{
  139. title: i18n.t('screens.settings.dashboardEdit.title'),
  140. }}
  141. />
  142. <MainStack.Screen
  143. name={MainRoutes.About}
  144. component={AboutScreen}
  145. options={{
  146. title: i18n.t('screens.about.title'),
  147. }}
  148. />
  149. <MainStack.Screen
  150. name={MainRoutes.Dependencies}
  151. component={AboutDependenciesScreen}
  152. options={{
  153. title: i18n.t('screens.about.libs'),
  154. }}
  155. />
  156. <MainStack.Screen
  157. name={MainRoutes.Debug}
  158. component={DebugScreen}
  159. options={{
  160. title: i18n.t('screens.about.debug'),
  161. }}
  162. />
  163. <MainStack.Screen
  164. name={MainRoutes.GameStart}
  165. component={GameStartScreen}
  166. options={{
  167. title: i18n.t('screens.game.title'),
  168. headerStyle: {
  169. backgroundColor: 'transparent',
  170. },
  171. }}
  172. />
  173. <MainStack.Screen
  174. name={MainRoutes.GameMain}
  175. component={GameMainScreen}
  176. options={{
  177. title: i18n.t('screens.game.title'),
  178. }}
  179. />
  180. <MainStack.Screen
  181. name={MainRoutes.Login}
  182. component={LoginScreen}
  183. options={{
  184. title: i18n.t('screens.login.title'),
  185. headerStyle: {
  186. backgroundColor: 'transparent',
  187. },
  188. }}
  189. />
  190. <MainStack.Screen
  191. name={MainRoutes.Website}
  192. component={WebsiteScreen}
  193. options={{
  194. title: '',
  195. }}
  196. />
  197. <MainStack.Screen
  198. name={MainRoutes.SelfMenu}
  199. component={SelfMenuScreen}
  200. options={{
  201. title: i18n.t('screens.menu.title'),
  202. }}
  203. />
  204. <MainStack.Screen
  205. name={MainRoutes.Proximo}
  206. component={ProximoMainScreen}
  207. options={{
  208. title: i18n.t('screens.proximo.title'),
  209. }}
  210. />
  211. <MainStack.Screen
  212. name={MainRoutes.ProximoList}
  213. component={ProximoListScreen}
  214. options={{
  215. title: i18n.t('screens.proximo.articleList'),
  216. }}
  217. />
  218. <MainStack.Screen
  219. name={MainRoutes.ProximoAbout}
  220. component={ProximoAboutScreen}
  221. options={{
  222. title: i18n.t('screens.proximo.title'),
  223. }}
  224. />
  225. <MainStack.Screen
  226. name={MainRoutes.Profile}
  227. component={ProfileScreen}
  228. options={{
  229. title: i18n.t('screens.profile.title'),
  230. }}
  231. />
  232. <MainStack.Screen
  233. name={MainRoutes.ClubList}
  234. component={ClubListScreen}
  235. options={{
  236. title: i18n.t('screens.clubs.title'),
  237. }}
  238. />
  239. <MainStack.Screen
  240. name={MainRoutes.ClubInformation}
  241. component={ClubDisplayScreen}
  242. options={{
  243. title: i18n.t('screens.clubs.details'),
  244. }}
  245. />
  246. <MainStack.Screen
  247. name={MainRoutes.ClubAbout}
  248. component={ClubAboutScreen}
  249. options={{
  250. title: i18n.t('screens.clubs.title'),
  251. }}
  252. />
  253. <MainStack.Screen
  254. name={MainRoutes.EquipmentList}
  255. component={EquipmentScreen}
  256. options={{
  257. title: i18n.t('screens.equipment.title'),
  258. }}
  259. />
  260. <MainStack.Screen
  261. name={MainRoutes.EquipmentRent}
  262. component={EquipmentLendScreen}
  263. options={{
  264. title: i18n.t('screens.equipment.book'),
  265. }}
  266. />
  267. <MainStack.Screen
  268. name={MainRoutes.EquipmentConfirm}
  269. component={EquipmentConfirmScreen}
  270. options={{
  271. title: i18n.t('screens.equipment.confirm'),
  272. }}
  273. />
  274. <MainStack.Screen
  275. name={MainRoutes.Vote}
  276. component={VoteScreen}
  277. options={{
  278. title: i18n.t('screens.vote.title'),
  279. }}
  280. />
  281. <MainStack.Screen
  282. name={MainRoutes.Feedback}
  283. component={BugReportScreen}
  284. options={{
  285. title: i18n.t('screens.feedback.title'),
  286. }}
  287. />
  288. </>
  289. );
  290. }
  291. function MainStackComponent(props: {
  292. showIntro: boolean;
  293. createTabNavigator: () => React.ReactElement;
  294. }) {
  295. const { showIntro, createTabNavigator } = props;
  296. return (
  297. <MainStack.Navigator
  298. initialRouteName={showIntro ? MainRoutes.Intro : MainRoutes.Main}
  299. headerMode={'screen'}
  300. >
  301. {showIntro ? getIntroScreens() : getRegularScreens(createTabNavigator)}
  302. </MainStack.Navigator>
  303. );
  304. }
  305. type PropsType = {
  306. defaultHomeRoute: string | null;
  307. defaultHomeData: { [key: string]: string };
  308. };
  309. export default function MainNavigator(props: PropsType) {
  310. const { preferences } = usePreferences();
  311. const showIntro = getPreferenceBool(PreferenceKeys.showIntro, preferences);
  312. return (
  313. <MainStackComponent
  314. showIntro={showIntro !== false}
  315. createTabNavigator={() => <TabNavigator {...props} />}
  316. />
  317. );
  318. }