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.

TabNavigator.tsx 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
  22. import { Title, useTheme } from 'react-native-paper';
  23. import { StyleSheet } from 'react-native';
  24. import i18n from 'i18n-js';
  25. import { View } from 'react-native-animatable';
  26. import HomeScreen from '../screens/Home/HomeScreen';
  27. import PlanningScreen from '../screens/Planning/PlanningScreen';
  28. import PlanningDisplayScreen from '../screens/Planning/PlanningDisplayScreen';
  29. import ProxiwashScreen from '../screens/Proxiwash/ProxiwashScreen';
  30. import ProxiwashAboutScreen from '../screens/Proxiwash/ProxiwashAboutScreen';
  31. import PlanexScreen from '../screens/Planex/PlanexScreen';
  32. import AsyncStorageManager from '../managers/AsyncStorageManager';
  33. import ClubDisplayScreen from '../screens/Amicale/Clubs/ClubDisplayScreen';
  34. import ScannerScreen from '../screens/Home/ScannerScreen';
  35. import FeedItemScreen from '../screens/Home/FeedItemScreen';
  36. import GroupSelectionScreen from '../screens/Planex/GroupSelectionScreen';
  37. import CustomTabBar from '../components/Tabbar/CustomTabBar';
  38. import WebsitesHomeScreen from '../screens/Services/ServicesScreen';
  39. import ServicesSectionScreen from '../screens/Services/ServicesSectionScreen';
  40. import AmicaleContactScreen from '../screens/Amicale/AmicaleContactScreen';
  41. import Mascot, { MASCOT_STYLE } from '../components/Mascot/Mascot';
  42. const styles = StyleSheet.create({
  43. header: {
  44. flexDirection: 'row',
  45. },
  46. mascot: {
  47. width: 50,
  48. },
  49. title: {
  50. marginLeft: 10,
  51. marginTop: 'auto',
  52. marginBottom: 'auto',
  53. },
  54. });
  55. const ServicesStack = createStackNavigator();
  56. function ServicesStackComponent() {
  57. return (
  58. <ServicesStack.Navigator initialRouteName={'index'} headerMode={'screen'}>
  59. <ServicesStack.Screen
  60. name={'index'}
  61. component={WebsitesHomeScreen}
  62. options={{ title: i18n.t('screens.services.title') }}
  63. />
  64. <ServicesStack.Screen
  65. name={'services-section'}
  66. component={ServicesSectionScreen}
  67. options={{ title: 'SECTION' }}
  68. />
  69. <ServicesStack.Screen
  70. name={'amicale-contact'}
  71. component={AmicaleContactScreen}
  72. options={{ title: i18n.t('screens.amicaleAbout.title') }}
  73. />
  74. </ServicesStack.Navigator>
  75. );
  76. }
  77. const ProxiwashStack = createStackNavigator();
  78. function ProxiwashStackComponent() {
  79. return (
  80. <ProxiwashStack.Navigator initialRouteName={'index'} headerMode={'screen'}>
  81. <ProxiwashStack.Screen
  82. name={'index-contact'}
  83. component={ProxiwashScreen}
  84. options={{ title: i18n.t('screens.proxiwash.title') }}
  85. />
  86. <ProxiwashStack.Screen
  87. name={'proxiwash-about'}
  88. component={ProxiwashAboutScreen}
  89. options={{ title: i18n.t('screens.proxiwash.title') }}
  90. />
  91. </ProxiwashStack.Navigator>
  92. );
  93. }
  94. const PlanningStack = createStackNavigator();
  95. function PlanningStackComponent() {
  96. return (
  97. <PlanningStack.Navigator initialRouteName={'index'} headerMode={'screen'}>
  98. <PlanningStack.Screen
  99. name={'index'}
  100. component={PlanningScreen}
  101. options={{ title: i18n.t('screens.planning.title') }}
  102. />
  103. <PlanningStack.Screen
  104. name={'planning-information'}
  105. component={PlanningDisplayScreen}
  106. options={{ title: i18n.t('screens.planning.eventDetails') }}
  107. />
  108. </PlanningStack.Navigator>
  109. );
  110. }
  111. const HomeStack = createStackNavigator();
  112. function HomeStackComponent(
  113. initialRoute: string | null,
  114. defaultData: { [key: string]: string }
  115. ) {
  116. let params;
  117. if (initialRoute) {
  118. params = { data: defaultData, nextScreen: initialRoute, shouldOpen: true };
  119. }
  120. const { colors } = useTheme();
  121. return (
  122. <HomeStack.Navigator initialRouteName={'index'} headerMode={'screen'}>
  123. <HomeStack.Screen
  124. name={'index'}
  125. component={HomeScreen}
  126. options={{
  127. title: i18n.t('screens.home.title'),
  128. headerStyle: {
  129. backgroundColor: colors.surface,
  130. },
  131. headerTitle: (headerProps) => (
  132. <View style={styles.header}>
  133. <Mascot
  134. style={styles.mascot}
  135. emotion={MASCOT_STYLE.RANDOM}
  136. animated
  137. entryAnimation={{
  138. animation: 'bounceIn',
  139. duration: 1000,
  140. }}
  141. loopAnimation={{
  142. animation: 'pulse',
  143. duration: 2000,
  144. iterationCount: 'infinite',
  145. }}
  146. />
  147. <Title style={styles.title}>{headerProps.children}</Title>
  148. </View>
  149. ),
  150. }}
  151. initialParams={params}
  152. />
  153. <HomeStack.Screen
  154. name={'scanner'}
  155. component={ScannerScreen}
  156. options={{ title: i18n.t('screens.scanner.title') }}
  157. />
  158. <HomeStack.Screen
  159. name={'club-information'}
  160. component={ClubDisplayScreen}
  161. options={{
  162. title: i18n.t('screens.clubs.details'),
  163. }}
  164. />
  165. <HomeStack.Screen
  166. name={'feed-information'}
  167. component={FeedItemScreen}
  168. options={{
  169. title: i18n.t('screens.home.feed'),
  170. }}
  171. />
  172. <HomeStack.Screen
  173. name={'planning-information'}
  174. component={PlanningDisplayScreen}
  175. options={{
  176. title: i18n.t('screens.planning.eventDetails'),
  177. }}
  178. />
  179. </HomeStack.Navigator>
  180. );
  181. }
  182. const PlanexStack = createStackNavigator();
  183. function PlanexStackComponent() {
  184. return (
  185. <PlanexStack.Navigator initialRouteName={'index'} headerMode={'screen'}>
  186. <PlanexStack.Screen
  187. name={'index'}
  188. component={PlanexScreen}
  189. options={{
  190. title: i18n.t('screens.planex.title'),
  191. }}
  192. />
  193. <PlanexStack.Screen
  194. name={'group-select'}
  195. component={GroupSelectionScreen}
  196. options={{
  197. title: '',
  198. }}
  199. />
  200. </PlanexStack.Navigator>
  201. );
  202. }
  203. const Tab = createBottomTabNavigator();
  204. type PropsType = {
  205. defaultHomeRoute: string | null;
  206. defaultHomeData: { [key: string]: string };
  207. };
  208. const ICONS: {
  209. [key: string]: {
  210. normal: string;
  211. focused: string;
  212. };
  213. } = {
  214. services: {
  215. normal: 'account-circle-outline',
  216. focused: 'account-circle',
  217. },
  218. proxiwash: {
  219. normal: 'tshirt-crew-outline',
  220. focused: 'tshirt-crew',
  221. },
  222. home: {
  223. normal: '',
  224. focused: '',
  225. },
  226. planning: {
  227. normal: 'calendar-range-outline',
  228. focused: 'calendar-range',
  229. },
  230. planex: {
  231. normal: 'clock-outline',
  232. focused: 'clock',
  233. },
  234. };
  235. export default class TabNavigator extends React.Component<PropsType> {
  236. defaultRoute: string;
  237. createHomeStackComponent: () => any;
  238. constructor(props: PropsType) {
  239. super(props);
  240. this.defaultRoute = 'home';
  241. if (!props.defaultHomeRoute) {
  242. this.defaultRoute = AsyncStorageManager.getString(
  243. AsyncStorageManager.PREFERENCES.defaultStartScreen.key
  244. ).toLowerCase();
  245. }
  246. this.createHomeStackComponent = () =>
  247. HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
  248. }
  249. render() {
  250. const LABELS: {
  251. [key: string]: string;
  252. } = {
  253. services: i18n.t('screens.services.title'),
  254. proxiwash: i18n.t('screens.proxiwash.title'),
  255. home: i18n.t('screens.home.title'),
  256. planning: i18n.t('screens.planning.title'),
  257. planex: i18n.t('screens.planex.title'),
  258. };
  259. return (
  260. <Tab.Navigator
  261. initialRouteName={this.defaultRoute}
  262. tabBar={(tabProps) => (
  263. <CustomTabBar {...tabProps} labels={LABELS} icons={ICONS} />
  264. )}
  265. >
  266. <Tab.Screen
  267. name={'services'}
  268. component={ServicesStackComponent}
  269. options={{ title: i18n.t('screens.services.title') }}
  270. />
  271. <Tab.Screen
  272. name={'proxiwash'}
  273. component={ProxiwashStackComponent}
  274. options={{ title: i18n.t('screens.proxiwash.title') }}
  275. />
  276. <Tab.Screen
  277. name={'home'}
  278. component={this.createHomeStackComponent}
  279. options={{ title: i18n.t('screens.home.title') }}
  280. />
  281. <Tab.Screen
  282. name={'planning'}
  283. component={PlanningStackComponent}
  284. options={{ title: i18n.t('screens.planning.title') }}
  285. />
  286. <Tab.Screen
  287. name={'planex'}
  288. component={PlanexStackComponent}
  289. options={{ title: i18n.t('screens.planex.title') }}
  290. />
  291. </Tab.Navigator>
  292. );
  293. }
  294. }