2017-05-16 21:57:09 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux'
|
2017-07-16 18:06:05 +02:00
|
|
|
import { View, Text, Button, StyleSheet, TouchableOpacity, Picker } from 'react-native';
|
2017-07-22 00:42:24 +02:00
|
|
|
import Icon from 'react-native-vector-icons/Ionicons';
|
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-07-21 23:40:02 +02:00
|
|
|
import { globalStyle } from 'lib/components/global-style.js';
|
2017-05-16 21:57:09 +02:00
|
|
|
|
2017-07-16 01:30:54 +02:00
|
|
|
let styleObject = {
|
2017-07-21 23:40:02 +02:00
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 10,
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
alignItems: 'center',
|
|
|
|
shadowColor: '#000000',
|
|
|
|
elevation: 5,
|
|
|
|
},
|
|
|
|
folderPicker: {
|
|
|
|
height: 30,
|
|
|
|
flex:1,
|
|
|
|
color: globalStyle.color,
|
2017-07-22 19:21:39 +02:00
|
|
|
// Note: cannot set backgroundStyle as that would remove the arrow in the component
|
2017-07-21 23:40:02 +02:00
|
|
|
},
|
2017-05-16 22:25:19 +02:00
|
|
|
divider: {
|
|
|
|
borderBottomWidth: 1,
|
2017-07-21 23:40:02 +02:00
|
|
|
borderColor: globalStyle.dividerColor,
|
|
|
|
backgroundColor: "#0000ff"
|
2017-05-16 22:25:19 +02:00
|
|
|
},
|
2017-07-16 01:30:54 +02:00
|
|
|
sideMenuButton: {
|
|
|
|
flex: 1,
|
2017-07-22 18:36:55 +02:00
|
|
|
alignItems: 'center',
|
2017-07-22 00:42:24 +02:00
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
paddingLeft: globalStyle.marginLeft,
|
|
|
|
paddingRight: 5,
|
|
|
|
marginRight: 2,
|
2017-07-16 01:30:54 +02:00
|
|
|
},
|
2017-07-23 00:52:24 +02:00
|
|
|
iconButton: {
|
2017-07-16 01:30:54 +02:00
|
|
|
flex: 1,
|
2017-07-22 00:42:24 +02:00
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
2017-07-16 01:30:54 +02:00
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
},
|
2017-07-16 12:17:40 +02:00
|
|
|
saveButton: {
|
|
|
|
flex: 1,
|
2017-07-22 18:36:55 +02:00
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2017-07-16 12:17:40 +02:00
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
marginRight: 10,
|
2017-07-22 18:36:55 +02:00
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: globalStyle.color,
|
|
|
|
borderRadius: 10,
|
2017-07-16 12:17:40 +02:00
|
|
|
},
|
|
|
|
saveButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
2017-07-22 18:36:55 +02:00
|
|
|
color: globalStyle.color,
|
2017-07-16 12:17:40 +02:00
|
|
|
fontWeight: 'bold',
|
2017-07-22 18:36:55 +02:00
|
|
|
},
|
|
|
|
saveButtonIcon: {
|
|
|
|
fontSize: 20,
|
|
|
|
color: globalStyle.color,
|
|
|
|
marginRight: 5,
|
2017-07-16 12:17:40 +02:00
|
|
|
},
|
2017-07-21 23:40:02 +02:00
|
|
|
contextMenuTrigger: {
|
|
|
|
fontSize: 25,
|
|
|
|
paddingRight: globalStyle.marginRight,
|
|
|
|
color: globalStyle.color,
|
2017-07-22 18:36:55 +02:00
|
|
|
fontWeight: 'bold',
|
2017-07-21 23:40:02 +02:00
|
|
|
},
|
|
|
|
contextMenu: {
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
},
|
|
|
|
contextMenuItem: {
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
},
|
|
|
|
contextMenuItemText: {
|
|
|
|
flex: 1,
|
|
|
|
height: 40,
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
paddingLeft: globalStyle.marginLeft,
|
|
|
|
paddingRight: globalStyle.marginRight,
|
|
|
|
color: globalStyle.color,
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
},
|
|
|
|
titleText: {
|
|
|
|
flex: 1,
|
2017-07-22 00:42:24 +02:00
|
|
|
marginLeft: 0,
|
2017-07-21 23:40:02 +02:00
|
|
|
color: globalStyle.color,
|
|
|
|
}
|
2017-07-16 01:30:54 +02:00
|
|
|
};
|
|
|
|
|
2017-07-22 18:36:55 +02:00
|
|
|
styleObject.topIcon = Object.assign({}, globalStyle.icon);
|
|
|
|
styleObject.topIcon.flex = 1;
|
|
|
|
styleObject.topIcon.textAlignVertical = 'center';
|
|
|
|
|
2017-07-23 00:52:24 +02:00
|
|
|
styleObject.backButton = Object.assign({}, styleObject.iconButton);
|
|
|
|
styleObject.backButton.marginRight = 1;
|
|
|
|
|
2017-07-22 18:36:55 +02:00
|
|
|
styleObject.backButtonDisabled = Object.assign({}, styleObject.backButton, { opacity: globalStyle.disabledOpacity });
|
|
|
|
styleObject.saveButtonDisabled = Object.assign({}, styleObject.saveButton, { opacity: globalStyle.disabledOpacity });
|
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-07-23 00:52:24 +02:00
|
|
|
searchButton_press() {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Search',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-07-23 20:26:50 +02:00
|
|
|
config_press() {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'Config',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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}>
|
2017-07-22 18:36:55 +02:00
|
|
|
<Icon name='md-menu' style={styleObject.topIcon} />
|
2017-07-16 01:30:54 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function backButton(styles, onPress, disabled) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled}>
|
|
|
|
<View style={disabled ? styles.backButtonDisabled : styles.backButton}>
|
2017-07-22 18:36:55 +02:00
|
|
|
<Icon name='md-arrow-back' style={styles.topIcon} />
|
2017-07-16 01:30:54 +02:00
|
|
|
</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}>
|
2017-07-22 18:36:55 +02:00
|
|
|
{ disabled && <Icon name='md-checkmark' style={styles.saveButtonIcon} /> }
|
2017-07-16 12:17:40 +02:00
|
|
|
<Text style={styles.saveButtonText}>Save</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-23 00:52:24 +02:00
|
|
|
function searchButton(styles, onPress) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<View style={styles.iconButton}>
|
|
|
|
<Icon name='md-search' style={styles.topIcon} />
|
|
|
|
</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-07-21 23:40:02 +02:00
|
|
|
<MenuOption value={o.onPress} key={'menuOption_' + key++} style={styles.contextMenuItem}>
|
|
|
|
<Text style={styles.contextMenuItemText}>{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(
|
2017-07-21 23:40:02 +02:00
|
|
|
<MenuOption value={() => this.log_press()} key={'menuOption_' + key++} style={styles.contextMenuItem}>
|
|
|
|
<Text style={styles.contextMenuItemText}>{_('Log')}</Text>
|
2017-07-07 19:19:24 +02:00
|
|
|
</MenuOption>);
|
2017-05-16 23:46:21 +02:00
|
|
|
|
2017-07-10 21:16:59 +02:00
|
|
|
menuOptionComponents.push(
|
2017-07-21 23:40:02 +02:00
|
|
|
<MenuOption value={() => this.status_press()} key={'menuOption_' + key++} style={styles.contextMenuItem}>
|
|
|
|
<Text style={styles.contextMenuItemText}>{_('Status')}</Text>
|
2017-07-10 21:16:59 +02:00
|
|
|
</MenuOption>);
|
|
|
|
|
2017-07-23 20:26:50 +02:00
|
|
|
if (menuOptionComponents.length) {
|
|
|
|
menuOptionComponents.push(<View key={'menuOption_' + key++} style={styles.divider}/>);
|
|
|
|
}
|
|
|
|
|
|
|
|
menuOptionComponents.push(
|
|
|
|
<MenuOption value={() => this.config_press()} key={'menuOption_' + key++} style={styles.contextMenuItem}>
|
|
|
|
<Text style={styles.contextMenuItemText}>{_('Configuration')}</Text>
|
|
|
|
</MenuOption>);
|
|
|
|
|
2017-07-16 18:06:05 +02:00
|
|
|
const createTitleComponent = () => {
|
|
|
|
const p = this.props.titlePicker;
|
|
|
|
if (p) {
|
|
|
|
let items = [];
|
|
|
|
for (let i = 0; i < p.items.length; i++) {
|
|
|
|
let item = p.items[i];
|
2017-07-21 23:40:02 +02:00
|
|
|
items.push(<Picker.Item label={item.label} value={item.value} key={item.value}/>);
|
2017-07-16 18:06:05 +02:00
|
|
|
}
|
|
|
|
return (
|
2017-07-21 23:40:02 +02:00
|
|
|
<Picker style={styles.folderPicker} selectedValue={p.selectedValue} onValueChange={(itemValue, itemIndex) => { if (p.onValueChange) p.onValueChange(itemValue, itemIndex); }}>
|
2017-07-16 18:06:05 +02:00
|
|
|
{ items }
|
|
|
|
</Picker>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let title = 'title' in this.props && this.props.title !== null ? this.props.title : _(this.props.navState.routeName);
|
2017-07-21 23:40:02 +02:00
|
|
|
return <Text style={styles.titleText}>{title}</Text>
|
2017-07-16 18:06:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const titleComp = createTitleComponent();
|
2017-05-16 22:25:19 +02:00
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
return (
|
2017-07-21 23:40:02 +02:00
|
|
|
<View style={styles.container} >
|
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-07-23 00:52:24 +02:00
|
|
|
{ titleComp }
|
|
|
|
{ searchButton(styles, () => this.searchButton_press()) }
|
2017-07-21 23:40:02 +02:00
|
|
|
<Menu onSelect={(value) => this.menu_select(value)} style={styles.contextMenu}>
|
2017-05-16 22:25:19 +02:00
|
|
|
<MenuTrigger>
|
2017-07-23 00:52:24 +02:00
|
|
|
<Text style={styles.contextMenuTrigger}> ⋮</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 };
|