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

95 lines
2.7 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 {
showBackButton() {
// Note: this is hardcoded for now because navigation.state doesn't tell whether
// it's possible to go back or not. Maybe it's possible to get this information
// from somewhere else.
2017-05-24 22:11:37 +02:00
return this.props.navState.routeName != 'Notes';
2017-05-16 21:57:09 +02:00
}
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-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-06 21:48:17 +02:00
// menuOptionComponents.push(
// <MenuOption value={1} key={'menuOption_' + key++}>
// <Text>{_('Configuration')}</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()} />
<Button disabled={!this.showBackButton()} 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(
(state) => {
2017-05-16 23:46:21 +02:00
return { user: state.user };
2017-05-16 21:57:09 +02:00
}
)(ScreenHeaderComponent)
export { ScreenHeader };