2017-05-16 21:57:09 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux'
|
2017-07-16 01:30:54 +02:00
|
|
|
import { View, Text, Button, StyleSheet, TouchableOpacity } 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';
|
2017-07-06 20:58:01 +02:00
|
|
|
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-07-16 01:30:54 +02:00
|
|
|
let styleObject = {
|
2017-05-16 22:25:19 +02:00
|
|
|
divider: {
|
|
|
|
marginVertical: 5,
|
|
|
|
marginHorizontal: 2,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderColor: '#ccc'
|
|
|
|
},
|
2017-07-16 01:30:54 +02:00
|
|
|
sideMenuButton: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: "#0482E3",
|
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
marginRight: 10,
|
|
|
|
},
|
|
|
|
sideMenuButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
color: "#ffffff",
|
|
|
|
fontWeight: 'bold',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
backButton: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: "#0482E3",
|
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
marginRight: 10,
|
|
|
|
},
|
|
|
|
backButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
color: "#ffffff",
|
|
|
|
fontWeight: 'bold',
|
|
|
|
flex: 1,
|
|
|
|
},
|
2017-07-16 12:17:40 +02:00
|
|
|
saveButton: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: "#0482E3",
|
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
marginRight: 10,
|
|
|
|
},
|
|
|
|
saveButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
color: "#ffffff",
|
|
|
|
fontWeight: 'bold',
|
|
|
|
flex: 1,
|
|
|
|
},
|
2017-07-16 01:30:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
styleObject.backButtonDisabled = Object.assign({}, styleObject.backButton, { backgroundColor: "#c6c6c6" });
|
2017-07-16 12:17:40 +02:00
|
|
|
styleObject.saveButtonDisabled = Object.assign({}, styleObject.saveButton, { backgroundColor: "#c6c6c6" });
|
2017-07-16 01:30:54 +02:00
|
|
|
|
|
|
|
const styles = StyleSheet.create(styleObject);
|
2017-05-16 22:25:19 +02:00
|
|
|
|
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-07-10 21:16:59 +02:00
|
|
|
status_press() {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Status',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
render() {
|
2017-07-16 01:30:54 +02:00
|
|
|
|
|
|
|
function sideMenuButton(styles, onPress) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<View style={styles.sideMenuButton}>
|
|
|
|
<Text style={styles.sideMenuButtonText}>☰</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function backButton(styles, onPress, disabled) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled}>
|
|
|
|
<View style={disabled ? styles.backButtonDisabled : styles.backButton}>
|
|
|
|
<Text style={styles.backButtonText}><</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
function saveButton(styles, onPress, disabled, show) {
|
|
|
|
if (!show) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled}>
|
|
|
|
<View style={disabled ? styles.saveButtonDisabled : styles.saveButton}>
|
|
|
|
<Text style={styles.saveButtonText}>Save</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-07-10 21:16:59 +02:00
|
|
|
menuOptionComponents.push(
|
|
|
|
<MenuOption value={() => this.status_press()} key={'menuOption_' + key++}>
|
|
|
|
<Text>{_('Status')}</Text>
|
|
|
|
</MenuOption>);
|
|
|
|
|
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 (
|
2017-07-13 00:32:08 +02:00
|
|
|
<View style={{ flexDirection: 'row', paddingLeft: 10, paddingTop: 10, paddingBottom: 10, paddingRight: 0, backgroundColor: '#ffffff', alignItems: 'center' }} >
|
2017-07-16 01:30:54 +02:00
|
|
|
{ sideMenuButton(styles, () => this.sideMenuButton_press()) }
|
|
|
|
{ backButton(styles, () => this.backButton_press(), !this.props.historyCanGoBack) }
|
2017-07-16 12:17:40 +02:00
|
|
|
{ saveButton(styles, () => { if (this.props.onSaveButtonPress) this.props.onSaveButtonPress() }, this.props.saveButtonDisabled === true, this.props.showSaveButton === true) }
|
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>
|
2017-07-13 00:32:08 +02:00
|
|
|
<Text style={{ fontSize: 25 }}> ⋮ </Text>
|
2017-05-16 22:25:19 +02:00
|
|
|
</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 };
|