2019-07-29 15:43:53 +02:00
|
|
|
const React = require('react');
|
|
|
|
const Component = React.Component;
|
2019-07-29 15:58:33 +02:00
|
|
|
const { TouchableOpacity, Text, StyleSheet, ScrollView, View } = require('react-native');
|
2019-07-11 18:43:55 +02:00
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const Icon = require('react-native-vector-icons/Ionicons').default;
|
2020-06-10 23:08:59 +02:00
|
|
|
const { themeStyle } = require('lib/components/global-style.js');
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2020-02-09 16:51:12 +02:00
|
|
|
Icon.loadFont();
|
|
|
|
|
2019-07-11 18:43:55 +02:00
|
|
|
class SideMenuContentNoteComponent extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.styles_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
styles() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
|
|
|
if (this.styles_[this.props.theme]) return this.styles_[this.props.theme];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const styles = {
|
2019-07-11 18:43:55 +02:00
|
|
|
menu: {
|
|
|
|
flex: 1,
|
2019-07-29 15:43:53 +02:00
|
|
|
backgroundColor: theme.backgroundColor,
|
2019-07-11 18:43:55 +02:00
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
height: 36,
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
},
|
|
|
|
sidebarIcon: {
|
|
|
|
fontSize: 22,
|
|
|
|
color: theme.color,
|
|
|
|
},
|
2019-10-12 20:55:59 +02:00
|
|
|
sideButtonText: {
|
|
|
|
color: theme.color,
|
|
|
|
},
|
2019-07-11 18:43:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
styles.sideButton = Object.assign({}, styles.button, { flex: 0 });
|
2019-07-11 19:23:29 +02:00
|
|
|
styles.sideButtonDisabled = Object.assign({}, styles.sideButton, { opacity: 0.6 });
|
2019-07-11 18:43:55 +02:00
|
|
|
|
|
|
|
this.styles_[this.props.theme] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[this.props.theme];
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:23:29 +02:00
|
|
|
renderDivider(key) {
|
2020-06-10 23:08:59 +02:00
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
return <View style={{ marginTop: 15, marginBottom: 15, flex: -1, borderBottomWidth: 1, borderBottomColor: theme.dividerColor }} key={key}></View>;
|
2019-07-11 18:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderSideBarButton(key, title, iconName, onPressHandler) {
|
2019-07-11 19:23:29 +02:00
|
|
|
const content = (
|
|
|
|
<View key={key} style={onPressHandler ? this.styles().sideButton : this.styles().sideButtonDisabled}>
|
2019-07-29 15:43:53 +02:00
|
|
|
{!iconName ? null : <Icon name={iconName} style={this.styles().sidebarIcon} />}
|
2019-07-11 19:23:29 +02:00
|
|
|
<Text style={this.styles().sideButtonText}>{title}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!onPressHandler) return content;
|
|
|
|
|
2019-07-11 18:43:55 +02:00
|
|
|
return (
|
|
|
|
<TouchableOpacity key={key} onPress={onPressHandler}>
|
2019-07-11 19:23:29 +02:00
|
|
|
{content}
|
2019-07-11 18:43:55 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const items = [];
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2019-07-11 19:23:29 +02:00
|
|
|
const options = this.props.options ? this.props.options : [];
|
|
|
|
let dividerIndex = 0;
|
2019-07-11 18:43:55 +02:00
|
|
|
|
|
|
|
for (const option of options) {
|
2019-07-11 19:23:29 +02:00
|
|
|
if (option.isDivider) {
|
2019-09-19 23:51:18 +02:00
|
|
|
items.push(this.renderDivider(`divider_${dividerIndex++}`));
|
2019-07-11 19:23:29 +02:00
|
|
|
} else {
|
|
|
|
items.push(this.renderSideBarButton(option.title, option.title, null, option.onPress));
|
|
|
|
}
|
2019-07-11 18:43:55 +02:00
|
|
|
}
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const style = {
|
2019-07-29 15:43:53 +02:00
|
|
|
flex: 1,
|
2019-07-11 18:43:55 +02:00
|
|
|
borderRightWidth: 1,
|
2020-06-10 23:08:59 +02:00
|
|
|
borderRightColor: theme.dividerColor,
|
2019-07-11 18:43:55 +02:00
|
|
|
backgroundColor: theme.backgroundColor,
|
2019-07-11 19:44:26 +02:00
|
|
|
paddingTop: 10,
|
2019-07-11 18:43:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={style}>
|
2019-07-29 15:43:53 +02:00
|
|
|
<View style={{ flex: 1, opacity: this.props.opacity }}>
|
2019-07-11 18:43:55 +02:00
|
|
|
<ScrollView scrollsToTop={false} style={this.styles().menu}>
|
2019-07-29 15:43:53 +02:00
|
|
|
{items}
|
2019-07-11 18:43:55 +02:00
|
|
|
</ScrollView>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-29 15:43:53 +02:00
|
|
|
}
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2020-05-21 10:14:33 +02:00
|
|
|
const SideMenuContentNote = connect(state => {
|
2019-07-29 15:43:53 +02:00
|
|
|
return {
|
|
|
|
theme: state.settings.theme,
|
|
|
|
};
|
|
|
|
})(SideMenuContentNoteComponent);
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = { SideMenuContentNote };
|