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-11-05 18:58:23 +02:00
|
|
|
const { themeStyle } = require('./global-style.js');
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2023-01-04 14:54:13 +02:00
|
|
|
// We need this to suppress the useless warning
|
|
|
|
// https://github.com/oblador/react-native-vector-icons/issues/1465
|
2023-02-16 12:55:24 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2023-01-04 14:54:13 +02:00
|
|
|
Icon.loadFont().catch((error) => { console.info(error); });
|
2020-02-09 16:51:12 +02:00
|
|
|
|
2019-07-11 18:43:55 +02:00
|
|
|
class SideMenuContentNoteComponent extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.styles_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
styles() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
if (this.styles_[this.props.themeId]) return this.styles_[this.props.themeId];
|
2019-07-11 18:43:55 +02:00
|
|
|
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
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
this.styles_[this.props.themeId] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[this.props.themeId];
|
2019-07-11 18:43:55 +02:00
|
|
|
}
|
|
|
|
|
2019-07-11 19:23:29 +02:00
|
|
|
renderDivider(key) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2020-06-10 23:08:59 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-12 14:28: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() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2019-07-11 18:43:55 +02:00
|
|
|
|
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 {
|
2021-01-12 14:28:55 +02:00
|
|
|
items.push(this.renderSidebarButton(option.title, option.title, null, option.onPress));
|
2019-07-11 19:23:29 +02:00
|
|
|
}
|
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 {
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: state.settings.theme,
|
2019-07-29 15:43:53 +02:00
|
|
|
};
|
|
|
|
})(SideMenuContentNoteComponent);
|
2019-07-11 18:43:55 +02:00
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = { SideMenuContentNote };
|