Application Android et IOS pour l'amicale des élèves
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Sidebar.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. type Props = {
  12. navigation: Object,
  13. };
  14. type State = {
  15. active: string,
  16. };
  17. /**
  18. * Class used to define a navigation drawer
  19. */
  20. export default class SideBar extends React.Component<Props, State> {
  21. dataSet: Array<Object>;
  22. state = {
  23. active: 'Home',
  24. };
  25. /**
  26. * Generate the datasets
  27. *
  28. * @param props
  29. */
  30. constructor(props: Props) {
  31. super(props);
  32. // Dataset used to render the drawer
  33. // If the link field is defined, clicking on the item will open the link
  34. this.dataSet = [
  35. {
  36. name: "Amicale",
  37. route: "amicale",
  38. icon: "web",
  39. link: Amicale_LINK
  40. },
  41. {
  42. name: "Wiketud",
  43. route: "wiketud",
  44. icon: "wikipedia",
  45. link: WIKETUD_LINK
  46. },
  47. // {
  48. // name: i18n.t('screens.settings'),
  49. // route: "Settings",
  50. // icon: "settings",
  51. // },
  52. // {
  53. // name: i18n.t('screens.about'),
  54. // route: "About",
  55. // icon: "information",
  56. // },
  57. ];
  58. }
  59. /**
  60. * Navigate to the selected route, close the drawer, and mark the correct item as selected
  61. * @param route {string} The route name to navigate to
  62. */
  63. navigateToScreen(route: string) {
  64. this.props.navigation.navigate(route);
  65. this.props.navigation.closeDrawer();
  66. };
  67. render() {
  68. return (
  69. <Container>
  70. <Content
  71. bounces={false}
  72. style={{flex: 1, top: -1}}
  73. >
  74. <Image source={drawerCover} style={styles.drawerCover}/>
  75. <FlatList
  76. data={this.dataSet}
  77. extraData={this.state}
  78. keyExtractor={(item) => item.route}
  79. renderItem={({item}) =>
  80. <ListItem
  81. button
  82. noBorder
  83. selected={this.state.active === item.route}
  84. onPress={() => {
  85. if (item.link !== undefined)
  86. Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
  87. else
  88. this.navigateToScreen(item.route);
  89. }}
  90. >
  91. <Left>
  92. <CustomMaterialIcon
  93. icon={item.icon}
  94. active={this.state.active === item.route}
  95. />
  96. <Text style={styles.text}>
  97. {item.name}
  98. </Text>
  99. </Left>
  100. {item.types &&
  101. <Right style={{flex: 1}}>
  102. <Badge
  103. style={{
  104. borderRadius: 3,
  105. height: 25,
  106. width: 72,
  107. backgroundColor: item.bg
  108. }}
  109. >
  110. <Text
  111. style={styles.badgeText}
  112. >{`${item.types} Types`}</Text>
  113. </Badge>
  114. </Right>}
  115. </ListItem>}
  116. />
  117. </Content>
  118. </Container>
  119. );
  120. }
  121. }
  122. const styles = StyleSheet.create({
  123. drawerCover: {
  124. alignSelf: "stretch",
  125. height: deviceHeight / 4,
  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. });