1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ReactNativeClient/lib/components/screen-header.js

97 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-05-16 21:57:09 +02:00
import React, { Component } from 'react';
import { connect } from 'react-redux'
2017-05-16 22:25:19 +02:00
import { View, Text, Button, StyleSheet } from 'react-native';
2017-06-24 20:06:28 +02:00
import { Log } from 'lib/log.js';
2017-05-16 22:25:19 +02:00
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
2017-06-24 20:06:28 +02:00
import { _ } from 'lib/locale.js';
import { Setting } from 'lib/models/setting.js';
import { FileApi } from 'lib/file-api.js';
import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
2017-07-06 21:48:17 +02:00
import { reg } from 'lib/registry.js'
2017-05-16 21:57:09 +02:00
2017-05-16 22:25:19 +02:00
const styles = StyleSheet.create({
divider: {
marginVertical: 5,
marginHorizontal: 2,
borderBottomWidth: 1,
borderColor: '#ccc'
},
});
2017-05-16 21:57:09 +02:00
class ScreenHeaderComponent extends Component {
2017-06-06 22:01:43 +02:00
sideMenuButton_press() {
2017-05-24 21:27:13 +02:00
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
}
2017-06-06 22:01:43 +02:00
backButton_press() {
2017-05-16 21:57:09 +02:00
this.props.dispatch({ type: 'Navigation/BACK' });
}
2017-06-06 22:01:43 +02:00
menu_select(value) {
2017-05-16 22:25:19 +02:00
if (typeof(value) == 'function') {
value();
}
}
2017-07-07 19:19:24 +02:00
log_press() {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Log',
});
}
2017-05-16 21:57:09 +02:00
render() {
2017-05-16 23:46:21 +02:00
let key = 0;
2017-05-16 22:25:19 +02:00
let menuOptionComponents = [];
for (let i = 0; i < this.props.menuOptions.length; i++) {
let o = this.props.menuOptions[i];
menuOptionComponents.push(
2017-05-16 23:46:21 +02:00
<MenuOption value={o.onPress} key={'menuOption_' + key++}>
2017-05-16 22:25:19 +02:00
<Text>{o.title}</Text>
2017-05-16 23:46:21 +02:00
</MenuOption>);
}
if (menuOptionComponents.length) {
menuOptionComponents.push(<View key={'menuOption_' + key++} style={styles.divider}/>);
2017-05-16 22:25:19 +02:00
}
2017-07-07 19:19:24 +02:00
menuOptionComponents.push(
<MenuOption value={() => this.log_press()} key={'menuOption_' + key++}>
<Text>{_('Log')}</Text>
</MenuOption>);
2017-05-16 23:46:21 +02:00
2017-05-16 22:25:19 +02:00
let title = 'title' in this.props && this.props.title !== null ? this.props.title : _(this.props.navState.routeName);
2017-05-16 21:57:09 +02:00
return (
<View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} >
2017-06-06 22:01:43 +02:00
<Button title="☰" onPress={() => this.sideMenuButton_press()} />
2017-07-09 01:57:30 +02:00
<Button disabled={!this.props.historyCanGoBack} title="<" onPress={() => this.backButton_press()}></Button>
2017-05-16 22:25:19 +02:00
<Text style={{ flex:1, marginLeft: 10 }} >{title}</Text>
2017-06-06 22:01:43 +02:00
<Menu onSelect={(value) => this.menu_select(value)}>
2017-05-16 22:25:19 +02:00
<MenuTrigger>
<Text style={{ fontSize: 20 }}> &#8942; </Text>
</MenuTrigger>
<MenuOptions>
{ menuOptionComponents }
</MenuOptions>
</Menu>
2017-05-16 21:57:09 +02:00
</View>
);
}
}
2017-06-11 23:11:14 +02:00
ScreenHeaderComponent.defaultProps = {
menuOptions: [],
};
2017-05-16 21:57:09 +02:00
const ScreenHeader = connect(
2017-07-09 01:57:30 +02:00
(state) => {
return {
historyCanGoBack: state.historyCanGoBack,
};
}
2017-05-16 21:57:09 +02:00
)(ScreenHeaderComponent)
export { ScreenHeader };