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.

Sidebar.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. import ThemeManager from "../utils/ThemeManager";
  8. const deviceHeight = Dimensions.get("window").height;
  9. const drawerCover = require("../assets/drawer-cover.png");
  10. type Props = {
  11. navigation: Object,
  12. };
  13. type State = {
  14. active: string,
  15. };
  16. /**
  17. * Class used to define a navigation drawer
  18. */
  19. export default class SideBar extends React.Component<Props, State> {
  20. dataSet: Array<Object>;
  21. state = {
  22. active: 'Home',
  23. };
  24. /**
  25. * Generate the datasets
  26. *
  27. * @param props
  28. */
  29. constructor(props: Props) {
  30. super(props);
  31. // Dataset used to render the drawer
  32. // If the link field is defined, clicking on the item will open the link
  33. this.dataSet = [
  34. {
  35. name: "Amicale",
  36. route: "AmicaleScreen",
  37. icon: "web",
  38. },
  39. {
  40. name: "Wiketud",
  41. route: "WiketudScreen",
  42. icon: "wikipedia",
  43. },
  44. {
  45. name: "Tutor'INSA",
  46. route: "TutorInsaScreen",
  47. icon: "school",
  48. },
  49. {
  50. name: i18n.t('screens.availableRooms'),
  51. route: "AvailableRoomScreen",
  52. icon: "calendar-check",
  53. },
  54. {
  55. name: i18n.t('screens.menuSelf'),
  56. route: "SelfMenuScreen",
  57. icon: "silverware-fork-knife",
  58. },
  59. ];
  60. }
  61. /**
  62. * Navigate to the selected route
  63. * @param route {string} The route name to navigate to
  64. */
  65. navigateToScreen(route: string) {
  66. this.props.navigation.navigate(route);
  67. };
  68. render() {
  69. return (
  70. <Container style={{backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor}}>
  71. <Content
  72. bounces={false}
  73. style={{flex: 1, top: -1}}
  74. >
  75. <Image source={drawerCover} style={styles.drawerCover}/>
  76. <FlatList
  77. data={this.dataSet}
  78. extraData={this.state}
  79. keyExtractor={(item) => item.route}
  80. renderItem={({item}) =>
  81. <ListItem
  82. button
  83. noBorder
  84. selected={this.state.active === item.route}
  85. onPress={() => {
  86. if (item.link !== undefined)
  87. Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
  88. else
  89. this.navigateToScreen(item.route);
  90. }}
  91. >
  92. <Left>
  93. <CustomMaterialIcon
  94. icon={item.icon}
  95. active={this.state.active === item.route}
  96. />
  97. <Text style={styles.text}>
  98. {item.name}
  99. </Text>
  100. </Left>
  101. {item.types &&
  102. <Right style={{flex: 1}}>
  103. <Badge
  104. style={{
  105. borderRadius: 3,
  106. height: 25,
  107. width: 72,
  108. backgroundColor: item.bg
  109. }}
  110. >
  111. <Text
  112. style={styles.badgeText}
  113. >{`${item.types} Types`}</Text>
  114. </Badge>
  115. </Right>}
  116. </ListItem>}
  117. />
  118. </Content>
  119. </Container>
  120. );
  121. }
  122. }
  123. const styles = StyleSheet.create({
  124. drawerCover: {
  125. height: deviceHeight / 5,
  126. width: null,
  127. position: "relative",
  128. marginBottom: 10,
  129. marginTop: 20
  130. },
  131. text: {
  132. fontWeight: Platform.OS === "ios" ? "500" : "400",
  133. fontSize: 16,
  134. marginLeft: 20
  135. },
  136. badgeText: {
  137. fontSize: Platform.OS === "ios" ? 13 : 11,
  138. fontWeight: "400",
  139. textAlign: "center",
  140. marginTop: Platform.OS === "android" ? -3 : undefined
  141. }
  142. });