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.

SideMenu.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // @flow
  2. import * as React from 'react';
  3. import {Dimensions, FlatList, Image, Linking, Platform, StyleSheet} from 'react-native';
  4. import {Badge, Container, Content, Left, ListItem, Right, Text} from "native-base";
  5. import i18n from "i18n-js";
  6. import CustomMaterialIcon from '../components/CustomMaterialIcon';
  7. const deviceHeight = Dimensions.get("window").height;
  8. const drawerCover = require("../assets/drawer-cover.png");
  9. const WIKETUD_LINK = "https://www.etud.insa-toulouse.fr/wiketud";
  10. const Amicale_LINK = "https://www.etud.insa-toulouse.fr/~amicale";
  11. const TIMETABLE_LINK = "http://planex.insa-toulouse.fr";
  12. type Props = {
  13. navigation: Object,
  14. };
  15. type State = {
  16. active: string,
  17. };
  18. /**
  19. * Class used to define a navigation drawer
  20. */
  21. export default class SideBar extends React.Component<Props, State> {
  22. dataSet: Array<Object>;
  23. state = {
  24. active: 'Home',
  25. };
  26. /**
  27. * Generate the datasets
  28. *
  29. * @param props
  30. */
  31. constructor(props: Props) {
  32. super(props);
  33. // Dataset used to render the drawer
  34. // If the link field is defined, clicking on the item will open the link
  35. this.dataSet = [
  36. {
  37. name: i18n.t('screens.home'),
  38. route: "Home",
  39. icon: "home",
  40. },
  41. {
  42. name: i18n.t('screens.planning'),
  43. route: "Planning",
  44. icon: "calendar-range",
  45. },
  46. {
  47. name: "Proxiwash",
  48. route: "Proxiwash",
  49. icon: "washing-machine",
  50. },
  51. {
  52. name: "Proximo",
  53. route: "Proximo",
  54. icon: "shopping",
  55. },
  56. {
  57. name: "Amicale",
  58. route: "amicale",
  59. icon: "web",
  60. link: Amicale_LINK
  61. },
  62. {
  63. name: i18n.t('screens.timetable'),
  64. route: "timetable",
  65. icon: "timetable",
  66. link: TIMETABLE_LINK
  67. },
  68. {
  69. name: "Wiketud",
  70. route: "wiketud",
  71. icon: "wikipedia",
  72. link: WIKETUD_LINK
  73. },
  74. {
  75. name: i18n.t('screens.settings'),
  76. route: "Settings",
  77. icon: "settings",
  78. },
  79. {
  80. name: i18n.t('screens.about'),
  81. route: "About",
  82. icon: "information",
  83. },
  84. ];
  85. }
  86. /**
  87. * Navigate to the selected route, close the drawer, and mark the correct item as selected
  88. * @param route {string} The route name to navigate to
  89. */
  90. navigateToScreen(route: string) {
  91. this.props.navigation.navigate(route);
  92. this.props.navigation.closeDrawer();
  93. this.setState({active: route});
  94. };
  95. render() {
  96. return (
  97. <Container>
  98. <Content
  99. bounces={false}
  100. style={{flex: 1, top: -1}}
  101. >
  102. <Image source={drawerCover} style={styles.drawerCover}/>
  103. <FlatList
  104. data={this.dataSet}
  105. extraData={this.state}
  106. keyExtractor={(item) => item.route}
  107. renderItem={({item}) =>
  108. <ListItem
  109. button
  110. noBorder={item.name !== 'Wiketud' && item.name !== 'Proximo'} // Display a separator before settings and Amicale
  111. selected={this.state.active === item.route}
  112. onPress={() => {
  113. if (item.link !== undefined)
  114. Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
  115. else
  116. this.navigateToScreen(item.route);
  117. }}
  118. >
  119. <Left>
  120. <CustomMaterialIcon
  121. icon={item.icon}
  122. active={this.state.active === item.route}
  123. />
  124. <Text style={styles.text}>
  125. {item.name}
  126. </Text>
  127. </Left>
  128. {item.types &&
  129. <Right style={{flex: 1}}>
  130. <Badge
  131. style={{
  132. borderRadius: 3,
  133. height: 25,
  134. width: 72,
  135. backgroundColor: item.bg
  136. }}
  137. >
  138. <Text
  139. style={styles.badgeText}
  140. >{`${item.types} Types`}</Text>
  141. </Badge>
  142. </Right>}
  143. </ListItem>}
  144. />
  145. </Content>
  146. </Container>
  147. );
  148. }
  149. }
  150. const styles = StyleSheet.create({
  151. drawerCover: {
  152. alignSelf: "stretch",
  153. height: deviceHeight / 4,
  154. width: null,
  155. position: "relative",
  156. marginBottom: 10,
  157. marginTop: 20
  158. },
  159. text: {
  160. fontWeight: Platform.OS === "ios" ? "500" : "400",
  161. fontSize: 16,
  162. marginLeft: 20
  163. },
  164. badgeText: {
  165. fontSize: Platform.OS === "ios" ? 13 : 11,
  166. fontWeight: "400",
  167. textAlign: "center",
  168. marginTop: Platform.OS === "android" ? -3 : undefined
  169. }
  170. });