1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ReactNativeClient/lib/components/side-menu-content-note.js

116 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;
const { globalStyle, themeStyle } = require('lib/components/global-style.js');
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_ = {};
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
this.styles_[this.props.theme] = StyleSheet.create(styles);
return this.styles_[this.props.theme];
}
renderDivider(key) {
2019-07-29 15:43:53 +02:00
return <View style={{ marginTop: 15, marginBottom: 15, flex: -1, borderBottomWidth: 1, borderBottomColor: globalStyle.dividerColor }} key={key}></View>;
2019-07-11 18:43: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() {
const theme = themeStyle(this.props.theme);
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 {
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: globalStyle.dividerColor,
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
2019-07-29 15:43:53 +02:00
const SideMenuContentNote = connect(state => {
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 };