1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-mobile/components/side-menu-content-note.js

117 lines
2.9 KiB
JavaScript
Raw Normal View History

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
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() {
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_ = {};
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,
},
sideButtonText: {
color: theme.color,
},
2019-07-11 18:43:55 +02:00
};
styles.sideButton = Object.assign({}, styles.button, { flex: 0 });
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
}
renderDivider(key) {
2020-09-15 15:01:07 +02:00
const theme = themeStyle(this.props.themeId);
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) {
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} />}
<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}>
{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
const items = [];
2019-07-11 18:43:55 +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) {
if (option.isDivider) {
2019-09-19 23:51:18 +02:00
items.push(this.renderDivider(`divider_${dividerIndex++}`));
} else {
2021-01-12 14:28:55 +02:00
items.push(this.renderSidebarButton(option.title, option.title, null, option.onPress));
}
2019-07-11 18:43:55 +02:00
}
const style = {
2019-07-29 15:43:53 +02:00
flex: 1,
2019-07-11 18:43:55 +02:00
borderRightWidth: 1,
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
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 };