2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-08-06 13:28:11 +02:00
|
|
|
import {Dimensions, FlatList, Image, Linking, Platform, StyleSheet} from 'react-native';
|
|
|
|
import {Badge, Container, Content, Left, ListItem, Right, Text} from "native-base";
|
2019-06-25 22:20:24 +02:00
|
|
|
import i18n from "i18n-js";
|
2019-06-28 11:35:15 +02:00
|
|
|
import CustomMaterialIcon from '../components/CustomMaterialIcon';
|
2019-08-08 19:45:21 +02:00
|
|
|
import ThemeManager from "../utils/ThemeManager";
|
2019-06-25 22:20:24 +02:00
|
|
|
|
|
|
|
const deviceHeight = Dimensions.get("window").height;
|
|
|
|
|
|
|
|
const drawerCover = require("../assets/drawer-cover.png");
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
active: string,
|
|
|
|
};
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Class used to define a navigation drawer
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
export default class SideBar extends React.Component<Props, State> {
|
|
|
|
|
|
|
|
dataSet: Array<Object>;
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
state = {
|
|
|
|
active: 'Home',
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the datasets
|
|
|
|
*
|
|
|
|
* @param props
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
constructor(props: Props) {
|
2019-06-25 22:20:24 +02:00
|
|
|
super(props);
|
2019-08-06 13:28:11 +02:00
|
|
|
// Dataset used to render the drawer
|
|
|
|
// If the link field is defined, clicking on the item will open the link
|
2019-06-25 22:20:24 +02:00
|
|
|
this.dataSet = [
|
2019-07-31 14:43:19 +02:00
|
|
|
{
|
|
|
|
name: "Amicale",
|
2019-11-02 15:44:19 +01:00
|
|
|
route: "AmicaleScreen",
|
2019-07-31 14:43:19 +02:00
|
|
|
icon: "web",
|
2019-08-05 22:55:45 +02:00
|
|
|
},
|
2019-06-27 10:45:16 +02:00
|
|
|
{
|
|
|
|
name: "Wiketud",
|
2019-11-02 15:44:19 +01:00
|
|
|
route: "WiketudScreen",
|
2019-08-05 22:55:45 +02:00
|
|
|
icon: "wikipedia",
|
2019-06-27 10:45:16 +02:00
|
|
|
},
|
2019-09-19 22:33:28 +02:00
|
|
|
{
|
|
|
|
name: "Tutor'INSA",
|
2019-11-02 15:44:19 +01:00
|
|
|
route: "TutorInsaScreen",
|
2019-09-19 22:33:28 +02:00
|
|
|
icon: "school",
|
2019-11-02 15:44:19 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-07 17:58:02 +01:00
|
|
|
name: i18n.t('screens.availableRooms'),
|
2019-11-02 15:44:19 +01:00
|
|
|
route: "AvailableRoomScreen",
|
|
|
|
icon: "calendar-check",
|
2019-09-19 22:33:28 +02:00
|
|
|
},
|
2019-08-08 13:57:03 +02:00
|
|
|
{
|
|
|
|
name: i18n.t('screens.menuSelf'),
|
|
|
|
route: "SelfMenuScreen",
|
|
|
|
icon: "silverware-fork-knife",
|
|
|
|
},
|
2019-06-25 22:20:24 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
2019-10-06 12:44:40 +02:00
|
|
|
* Navigate to the selected route
|
2019-06-29 15:43:57 +02:00
|
|
|
* @param route {string} The route name to navigate to
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
navigateToScreen(route: string) {
|
2019-06-25 22:20:24 +02:00
|
|
|
this.props.navigation.navigate(route);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-08-08 19:45:21 +02:00
|
|
|
<Container style={{backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor}}>
|
2019-06-25 22:20:24 +02:00
|
|
|
<Content
|
|
|
|
bounces={false}
|
2019-06-27 10:45:16 +02:00
|
|
|
style={{flex: 1, top: -1}}
|
2019-06-25 22:20:24 +02:00
|
|
|
>
|
2019-06-27 10:45:16 +02:00
|
|
|
<Image source={drawerCover} style={styles.drawerCover}/>
|
2019-06-25 22:20:24 +02:00
|
|
|
<FlatList
|
|
|
|
data={this.dataSet}
|
|
|
|
extraData={this.state}
|
2019-06-29 13:37:21 +02:00
|
|
|
keyExtractor={(item) => item.route}
|
2019-06-25 22:20:24 +02:00
|
|
|
renderItem={({item}) =>
|
|
|
|
<ListItem
|
|
|
|
button
|
2019-08-07 10:24:35 +02:00
|
|
|
noBorder
|
2019-06-25 22:20:24 +02:00
|
|
|
selected={this.state.active === item.route}
|
2019-06-27 10:45:16 +02:00
|
|
|
onPress={() => {
|
2019-08-05 22:55:45 +02:00
|
|
|
if (item.link !== undefined)
|
|
|
|
Linking.openURL(item.link).catch((err) => console.error('Error opening link', err));
|
|
|
|
else
|
2019-06-27 10:45:16 +02:00
|
|
|
this.navigateToScreen(item.route);
|
|
|
|
}}
|
2019-06-25 22:20:24 +02:00
|
|
|
>
|
|
|
|
<Left>
|
2019-06-28 11:35:15 +02:00
|
|
|
<CustomMaterialIcon
|
|
|
|
icon={item.icon}
|
|
|
|
active={this.state.active === item.route}
|
2019-06-25 22:20:24 +02:00
|
|
|
/>
|
|
|
|
<Text style={styles.text}>
|
|
|
|
{item.name}
|
|
|
|
</Text>
|
|
|
|
</Left>
|
|
|
|
{item.types &&
|
2019-06-27 10:45:16 +02:00
|
|
|
<Right style={{flex: 1}}>
|
2019-06-25 22:20:24 +02:00
|
|
|
<Badge
|
|
|
|
style={{
|
|
|
|
borderRadius: 3,
|
|
|
|
height: 25,
|
|
|
|
width: 72,
|
|
|
|
backgroundColor: item.bg
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
style={styles.badgeText}
|
|
|
|
>{`${item.types} Types`}</Text>
|
|
|
|
</Badge>
|
|
|
|
</Right>}
|
|
|
|
</ListItem>}
|
|
|
|
/>
|
|
|
|
</Content>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
drawerCover: {
|
2019-08-22 11:41:34 +02:00
|
|
|
height: deviceHeight / 5,
|
2019-06-25 22:20:24 +02:00
|
|
|
width: null,
|
|
|
|
position: "relative",
|
|
|
|
marginBottom: 10,
|
|
|
|
marginTop: 20
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
fontWeight: Platform.OS === "ios" ? "500" : "400",
|
|
|
|
fontSize: 16,
|
|
|
|
marginLeft: 20
|
|
|
|
},
|
|
|
|
badgeText: {
|
|
|
|
fontSize: Platform.OS === "ios" ? 13 : 11,
|
|
|
|
fontWeight: "400",
|
|
|
|
textAlign: "center",
|
|
|
|
marginTop: Platform.OS === "android" ? -3 : undefined
|
|
|
|
}
|
|
|
|
});
|