Application Android et IOS pour l'amicale des élèves
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.

MainTabNavigator.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. import * as React from 'react';
  2. import {createStackNavigator, TransitionPresets} from '@react-navigation/stack';
  3. import {createBottomTabNavigator} from "@react-navigation/bottom-tabs";
  4. import HomeScreen from '../screens/Home/HomeScreen';
  5. import PlanningScreen from '../screens/Planning/PlanningScreen';
  6. import PlanningDisplayScreen from '../screens/Planning/PlanningDisplayScreen';
  7. import ProxiwashScreen from '../screens/Proxiwash/ProxiwashScreen';
  8. import ProxiwashAboutScreen from '../screens/Proxiwash/ProxiwashAboutScreen';
  9. import ProximoMainScreen from '../screens/Proximo/ProximoMainScreen';
  10. import ProximoListScreen from "../screens/Proximo/ProximoListScreen";
  11. import ProximoAboutScreen from "../screens/Proximo/ProximoAboutScreen";
  12. import PlanexScreen from '../screens/Planex/PlanexScreen';
  13. import AsyncStorageManager from "../managers/AsyncStorageManager";
  14. import {useTheme, withTheme} from 'react-native-paper';
  15. import i18n from "i18n-js";
  16. import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen";
  17. import ScannerScreen from "../screens/Home/ScannerScreen";
  18. import MaterialHeaderButtons, {Item} from "../components/Overrides/CustomHeaderButton";
  19. import FeedItemScreen from "../screens/Home/FeedItemScreen";
  20. import {createCollapsibleStack} from "react-navigation-collapsible";
  21. import GroupSelectionScreen from "../screens/Planex/GroupSelectionScreen";
  22. import CustomTabBar from "../components/Tabbar/CustomTabBar";
  23. const TAB_ICONS = {
  24. home: 'triangle',
  25. planning: 'calendar-range',
  26. proxiwash: 'tshirt-crew',
  27. proximo: 'cart',
  28. planex: 'clock',
  29. };
  30. const defaultScreenOptions = {
  31. gestureEnabled: true,
  32. cardOverlayEnabled: true,
  33. ...TransitionPresets.SlideFromRightIOS,
  34. };
  35. function getDrawerButton(navigation: Object) {
  36. return (
  37. <MaterialHeaderButtons left={true}>
  38. <Item title="menu" iconName="menu" onPress={navigation.openDrawer}/>
  39. </MaterialHeaderButtons>
  40. );
  41. }
  42. const ProximoStack = createStackNavigator();
  43. function ProximoStackComponent() {
  44. const {colors} = useTheme();
  45. return (
  46. <ProximoStack.Navigator
  47. initialRouteName="index"
  48. headerMode="float"
  49. screenOptions={defaultScreenOptions}
  50. >
  51. {createCollapsibleStack(
  52. <ProximoStack.Screen
  53. name="index"
  54. options={({navigation}) => {
  55. const openDrawer = getDrawerButton.bind(this, navigation);
  56. return {
  57. title: 'Proximo',
  58. headerLeft: openDrawer,
  59. headerStyle: {
  60. backgroundColor: colors.surface,
  61. },
  62. };
  63. }}
  64. component={ProximoMainScreen}
  65. />,
  66. {
  67. collapsedColor: 'transparent',
  68. useNativeDriver: true,
  69. }
  70. )}
  71. {createCollapsibleStack(
  72. <ProximoStack.Screen
  73. name="proximo-list"
  74. options={{
  75. title: i18n.t('screens.proximoArticles'),
  76. headerStyle: {
  77. backgroundColor: colors.surface,
  78. }
  79. }}
  80. component={ProximoListScreen}
  81. />,
  82. {
  83. collapsedColor: 'transparent',
  84. useNativeDriver: true,
  85. }
  86. )}
  87. <ProximoStack.Screen
  88. name="proximo-about"
  89. component={ProximoAboutScreen}
  90. options={{
  91. title: i18n.t('screens.proximo'),
  92. ...TransitionPresets.ModalSlideFromBottomIOS,
  93. }}
  94. />
  95. </ProximoStack.Navigator>
  96. );
  97. }
  98. const ProxiwashStack = createStackNavigator();
  99. function ProxiwashStackComponent() {
  100. const {colors} = useTheme();
  101. return (
  102. <ProxiwashStack.Navigator
  103. initialRouteName="index"
  104. headerMode='float'
  105. screenOptions={defaultScreenOptions}
  106. >
  107. {createCollapsibleStack(
  108. <ProxiwashStack.Screen
  109. name="index"
  110. component={ProxiwashScreen}
  111. options={({navigation}) => {
  112. const openDrawer = getDrawerButton.bind(this, navigation);
  113. return {
  114. title: i18n.t('screens.proxiwash'),
  115. headerLeft: openDrawer,
  116. headerStyle: {
  117. backgroundColor: colors.surface,
  118. },
  119. };
  120. }}
  121. />,
  122. {
  123. collapsedColor: 'transparent',
  124. useNativeDriver: true,
  125. }
  126. )}
  127. <ProxiwashStack.Screen
  128. name="proxiwash-about"
  129. component={ProxiwashAboutScreen}
  130. options={{
  131. title: i18n.t('screens.proxiwash'),
  132. ...TransitionPresets.ModalSlideFromBottomIOS,
  133. }}
  134. />
  135. </ProxiwashStack.Navigator>
  136. );
  137. }
  138. const PlanningStack = createStackNavigator();
  139. function PlanningStackComponent() {
  140. const {colors} = useTheme();
  141. return (
  142. <PlanningStack.Navigator
  143. initialRouteName="index"
  144. headerMode='float'
  145. screenOptions={defaultScreenOptions}
  146. >
  147. <PlanningStack.Screen
  148. name="index"
  149. component={PlanningScreen}
  150. options={({navigation}) => {
  151. const openDrawer = getDrawerButton.bind(this, navigation);
  152. return {
  153. title: i18n.t('screens.planning'),
  154. headerLeft: openDrawer
  155. };
  156. }}
  157. />
  158. <PlanningStack.Screen
  159. name="planning-information"
  160. component={PlanningDisplayScreen}
  161. options={{
  162. title: i18n.t('screens.planningDisplayScreen'),
  163. ...TransitionPresets.ModalSlideFromBottomIOS,
  164. }}
  165. />
  166. </PlanningStack.Navigator>
  167. );
  168. }
  169. const HomeStack = createStackNavigator();
  170. function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
  171. let data;
  172. if (initialRoute !== null)
  173. data = {data: defaultData, nextScreen: initialRoute, shouldOpen: true};
  174. const {colors} = useTheme();
  175. return (
  176. <HomeStack.Navigator
  177. initialRouteName={"index"}
  178. headerMode="float"
  179. screenOptions={defaultScreenOptions}
  180. >
  181. {createCollapsibleStack(
  182. <HomeStack.Screen
  183. name="index"
  184. component={HomeScreen}
  185. options={({navigation}) => {
  186. const openDrawer = getDrawerButton.bind(this, navigation);
  187. return {
  188. title: i18n.t('screens.home'),
  189. headerLeft: openDrawer,
  190. headerStyle: {
  191. backgroundColor: colors.surface,
  192. },
  193. };
  194. }}
  195. initialParams={data}
  196. />,
  197. {
  198. collapsedColor: 'transparent',
  199. useNativeDriver: true,
  200. }
  201. )}
  202. <HomeStack.Screen
  203. name="home-planning-information"
  204. component={PlanningDisplayScreen}
  205. options={{
  206. title: i18n.t('screens.planningDisplayScreen'),
  207. ...TransitionPresets.ModalSlideFromBottomIOS,
  208. }}
  209. />
  210. <HomeStack.Screen
  211. name="home-club-information"
  212. component={ClubDisplayScreen}
  213. options={({navigation}) => {
  214. return {
  215. title: i18n.t('screens.clubDisplayScreen'),
  216. ...TransitionPresets.ModalSlideFromBottomIOS,
  217. };
  218. }}
  219. />
  220. <HomeStack.Screen
  221. name="feed-information"
  222. component={FeedItemScreen}
  223. options={({navigation}) => {
  224. return {
  225. title: i18n.t('screens.feedDisplayScreen'),
  226. ...TransitionPresets.ModalSlideFromBottomIOS,
  227. };
  228. }}
  229. />
  230. <HomeStack.Screen
  231. name="scanner"
  232. component={ScannerScreen}
  233. options={({navigation}) => {
  234. return {
  235. title: i18n.t('screens.scanner'),
  236. ...TransitionPresets.ModalSlideFromBottomIOS,
  237. };
  238. }}
  239. />
  240. </HomeStack.Navigator>
  241. );
  242. }
  243. const PlanexStack = createStackNavigator();
  244. function PlanexStackComponent() {
  245. const {colors} = useTheme();
  246. return (
  247. <PlanexStack.Navigator
  248. initialRouteName="index"
  249. headerMode="float"
  250. screenOptions={defaultScreenOptions}
  251. >
  252. {createCollapsibleStack(
  253. <PlanexStack.Screen
  254. name="index"
  255. component={PlanexScreen}
  256. options={({navigation}) => {
  257. const openDrawer = getDrawerButton.bind(this, navigation);
  258. return {
  259. title: 'Planex',
  260. headerLeft: openDrawer,
  261. headerStyle: {
  262. backgroundColor: colors.surface,
  263. },
  264. };
  265. }}
  266. />,
  267. {
  268. collapsedColor: 'transparent',
  269. useNativeDriver: false, // native driver does not work with webview
  270. }
  271. )}
  272. {createCollapsibleStack(
  273. <PlanexStack.Screen
  274. name="group-select"
  275. component={GroupSelectionScreen}
  276. options={({navigation}) => {
  277. return {
  278. title: 'GroupSelectionScreen',
  279. headerStyle: {
  280. backgroundColor: colors.surface,
  281. },
  282. ...TransitionPresets.ModalSlideFromBottomIOS,
  283. };
  284. }}
  285. />,
  286. {
  287. collapsedColor: 'transparent',
  288. useNativeDriver: true,
  289. }
  290. )}
  291. </PlanexStack.Navigator>
  292. );
  293. }
  294. const Tab = createBottomTabNavigator();
  295. type Props = {
  296. defaultRoute: string | null,
  297. defaultData: Object
  298. }
  299. class TabNavigator extends React.Component<Props> {
  300. createHomeStackComponent: Object;
  301. defaultRoute: string;
  302. constructor(props) {
  303. super(props);
  304. this.defaultRoute = AsyncStorageManager.getInstance().preferences.defaultStartScreen.current.toLowerCase();
  305. if (props.defaultRoute !== null)
  306. this.defaultRoute = 'home';
  307. this.createHomeStackComponent = () => HomeStackComponent(props.defaultRoute, props.defaultData);
  308. }
  309. render() {
  310. return (
  311. <Tab.Navigator
  312. initialRouteName={this.defaultRoute}
  313. barStyle={{backgroundColor: this.props.theme.colors.surface, overflow: 'visible'}}
  314. screenOptions={({route}) => ({
  315. tabBarIcon: ({focused, color}) => {
  316. let icon = TAB_ICONS[route.name];
  317. icon = focused ? icon : icon + ('-outline');
  318. if (route.name !== "home")
  319. return icon;
  320. else
  321. return null;
  322. },
  323. tabBarLabel: route.name !== 'home' ? undefined : '',
  324. activeColor: this.props.theme.colors.primary,
  325. inactiveColor: this.props.theme.colors.tabIcon,
  326. })}
  327. tabBar={props => <CustomTabBar {...props} />}
  328. >
  329. <Tab.Screen
  330. name="proximo"
  331. option
  332. component={ProximoStackComponent}
  333. options={{title: i18n.t('screens.proximo')}}
  334. />
  335. <Tab.Screen
  336. name="planning"
  337. component={PlanningStackComponent}
  338. options={{title: i18n.t('screens.planning')}}
  339. />
  340. <Tab.Screen
  341. name="home"
  342. component={this.createHomeStackComponent}
  343. options={{title: i18n.t('screens.home')}}
  344. />
  345. <Tab.Screen
  346. name="proxiwash"
  347. component={ProxiwashStackComponent}
  348. options={{title: i18n.t('screens.proxiwash')}}
  349. />
  350. <Tab.Screen
  351. name="planex"
  352. component={PlanexStackComponent}
  353. options={{title: "Planex"}}
  354. />
  355. </Tab.Navigator>
  356. );
  357. }
  358. }
  359. export default withTheme(TabNavigator);