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.

Sidebar.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 RU_LINK = "http://m.insa-toulouse.fr/ru.html";
  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: "Amicale",
  38. route: "amicale",
  39. icon: "web",
  40. link: Amicale_LINK
  41. },
  42. {
  43. name: "Wiketud",
  44. route: "wiketud",
  45. icon: "wikipedia",
  46. link: WIKETUD_LINK
  47. },
  48. {
  49. name: i18n.t('screens.menuSelf'),
  50. route: "SelfMenuScreen",
  51. icon: "silverware-fork-knife",
  52. },
  53. ];
  54. }
  55. /**
  56. * Navigate to the selected route, close the drawer, and mark the correct item as selected
  57. * @param route {string} The route name to navigate to
  58. */
  59. navigateToScreen(route: string) {
  60. this.props.navigation.navigate(route);
  61. };
  62. render() {
  63. return (
  64. <Container>
  65. <Content
  66. bounces={false}
  67. style={{flex: 1, top: -1}}
  68. >
  69. <Image source={drawerCover} style={styles.drawerCover}/>
  70. <FlatList
  71. data={this.dataSet}
  72. extraData={this.state}
  73. keyExtractor={(item) => item.route}
  74. renderItem={({item}) =>
  75. <ListItem
  76. button
  77. noBorder
  78. selected={this.state.active === item.route}
  79. onPress={() => {
  80. if (item.link !== undefined)
  81. Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
  82. else
  83. this.navigateToScreen(item.route);
  84. }}
  85. >
  86. <Left>
  87. <CustomMaterialIcon
  88. icon={item.icon}
  89. active={this.state.active === item.route}
  90. />
  91. <Text style={styles.text}>
  92. {item.name}
  93. </Text>
  94. </Left>
  95. {item.types &&
  96. <Right style={{flex: 1}}>
  97. <Badge
  98. style={{
  99. borderRadius: 3,
  100. height: 25,
  101. width: 72,
  102. backgroundColor: item.bg
  103. }}
  104. >
  105. <Text
  106. style={styles.badgeText}
  107. >{`${item.types} Types`}</Text>
  108. </Badge>
  109. </Right>}
  110. </ListItem>}
  111. />
  112. </Content>
  113. </Container>
  114. );
  115. }
  116. }
  117. const styles = StyleSheet.create({
  118. drawerCover: {
  119. alignSelf: "stretch",
  120. height: deviceHeight / 4,
  121. width: null,
  122. position: "relative",
  123. marginBottom: 10,
  124. marginTop: 20
  125. },
  126. text: {
  127. fontWeight: Platform.OS === "ios" ? "500" : "400",
  128. fontSize: 16,
  129. marginLeft: 20
  130. },
  131. badgeText: {
  132. fontSize: Platform.OS === "ios" ? 13 : 11,
  133. fontWeight: "400",
  134. textAlign: "center",
  135. marginTop: Platform.OS === "android" ? -3 : undefined
  136. }
  137. });