2017-05-16 21:57:09 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux'
|
2017-07-31 20:19:58 +02:00
|
|
|
import { View, Text, Button, StyleSheet, TouchableOpacity, Picker, Image } 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-31 20:19:58 +02:00
|
|
|
// Rather than applying a padding to the whole bar, it is applied to each
|
|
|
|
// individual component (button, picker, etc.) so that the touchable areas
|
|
|
|
// are widder and to give more room to the picker component which has a larger
|
|
|
|
// default height.
|
|
|
|
const PADDING_V = 10;
|
|
|
|
|
2017-07-16 01:30:54 +02:00
|
|
|
let styleObject = {
|
2017-07-21 23:40:02 +02:00
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
2017-07-27 19:25:42 +02:00
|
|
|
backgroundColor: globalStyle.raisedBackgroundColor,
|
2017-07-21 23:40:02 +02:00
|
|
|
alignItems: 'center',
|
|
|
|
shadowColor: '#000000',
|
|
|
|
elevation: 5,
|
|
|
|
},
|
|
|
|
folderPicker: {
|
|
|
|
flex:1,
|
2017-07-27 19:25:42 +02:00
|
|
|
color: globalStyle.raisedHighlightedColor,
|
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-27 19:25:42 +02:00
|
|
|
backgroundColor: globalStyle.raisedBackgroundColor,
|
2017-07-22 00:42:24 +02:00
|
|
|
paddingLeft: globalStyle.marginLeft,
|
|
|
|
paddingRight: 5,
|
|
|
|
marginRight: 2,
|
2017-07-31 20:19:58 +02:00
|
|
|
paddingTop: PADDING_V,
|
|
|
|
paddingBottom: PADDING_V,
|
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-27 19:25:42 +02:00
|
|
|
backgroundColor: globalStyle.raisedBackgroundColor,
|
2017-07-16 01:30:54 +02:00
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
2017-07-31 20:19:58 +02:00
|
|
|
paddingTop: PADDING_V,
|
|
|
|
paddingBottom: PADDING_V,
|
2017-07-16 01:30:54 +02:00
|
|
|
},
|
2017-07-16 12:17:40 +02:00
|
|
|
saveButton: {
|
2017-07-31 20:19:58 +02:00
|
|
|
flex: 0,
|
2017-07-22 18:36:55 +02:00
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2017-07-31 20:19:58 +02:00
|
|
|
padding: 10,
|
2017-07-22 18:36:55 +02:00
|
|
|
borderWidth: 1,
|
2017-07-27 19:34:43 +02:00
|
|
|
borderColor: globalStyle.raisedHighlightedColor,
|
|
|
|
borderRadius: 4,
|
2017-07-31 20:19:58 +02:00
|
|
|
marginRight: 8,
|
2017-07-16 12:17:40 +02:00
|
|
|
},
|
|
|
|
saveButtonText: {
|
|
|
|
textAlignVertical: 'center',
|
2017-07-27 19:34:43 +02:00
|
|
|
color: globalStyle.raisedHighlightedColor,
|
2017-07-16 12:17:40 +02:00
|
|
|
fontWeight: 'bold',
|
2017-07-22 18:36:55 +02:00
|
|
|
},
|
2017-07-31 20:19:58 +02:00
|
|
|
savedButtonIcon: {
|
2017-07-22 18:36:55 +02:00
|
|
|
fontSize: 20,
|
2017-07-27 19:34:43 +02:00
|
|
|
color: globalStyle.raisedHighlightedColor,
|
2017-07-31 20:19:58 +02:00
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
},
|
|
|
|
saveButtonIcon: {
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
2017-07-16 12:17:40 +02:00
|
|
|
},
|
2017-07-21 23:40:02 +02:00
|
|
|
contextMenuTrigger: {
|
|
|
|
fontSize: 25,
|
|
|
|
paddingRight: globalStyle.marginRight,
|
2017-07-27 19:25:42 +02:00
|
|
|
color: globalStyle.raisedColor,
|
2017-07-22 18:36:55 +02:00
|
|
|
fontWeight: 'bold',
|
2017-07-21 23:40:02 +02:00
|
|
|
},
|
|
|
|
contextMenu: {
|
2017-07-27 19:25:42 +02:00
|
|
|
backgroundColor: globalStyle.raisedBackgroundColor,
|
2017-07-21 23:40:02 +02:00
|
|
|
},
|
|
|
|
contextMenuItem: {
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
|
|
|
},
|
|
|
|
contextMenuItemText: {
|
|
|
|
flex: 1,
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
paddingLeft: globalStyle.marginLeft,
|
|
|
|
paddingRight: globalStyle.marginRight,
|
2017-07-30 23:04:26 +02:00
|
|
|
paddingTop: globalStyle.itemMarginTop,
|
|
|
|
paddingBottom: globalStyle.itemMarginBottom,
|
2017-07-21 23:40:02 +02:00
|
|
|
color: globalStyle.color,
|
|
|
|
backgroundColor: globalStyle.backgroundColor,
|
2017-07-30 23:04:26 +02:00
|
|
|
fontSize: globalStyle.fontSize,
|
2017-07-21 23:40:02 +02:00
|
|
|
},
|
|
|
|
titleText: {
|
|
|
|
flex: 1,
|
2017-07-22 00:42:24 +02:00
|
|
|
marginLeft: 0,
|
2017-07-27 19:25:42 +02:00
|
|
|
color: globalStyle.raisedHighlightedColor,
|
|
|
|
fontWeight: 'bold',
|
2017-07-30 23:04:26 +02:00
|
|
|
fontSize: globalStyle.fontSize,
|
2017-07-21 23:40:02 +02:00
|
|
|
}
|
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-27 19:25:42 +02:00
|
|
|
styleObject.topIcon.color = globalStyle.raisedColor;
|
2017-07-22 18:36:55 +02:00
|
|
|
|
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-07-25 20:41:53 +02:00
|
|
|
this.props.dispatch({ type: 'NAV_BACK' });
|
2017-05-16 21:57:09 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 00:52:24 +02:00
|
|
|
searchButton_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-23 00:52:24 +02:00
|
|
|
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({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-07 19:19:24 +02:00
|
|
|
routeName: 'Log',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:16:59 +02:00
|
|
|
status_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-10 21:16:59 +02:00
|
|
|
routeName: 'Status',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-23 20:26:50 +02:00
|
|
|
config_press() {
|
|
|
|
this.props.dispatch({
|
2017-07-25 20:41:53 +02:00
|
|
|
type: 'NAV_GO',
|
2017-07-23 20:26:50 +02:00
|
|
|
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;
|
|
|
|
|
2017-07-31 20:19:58 +02:00
|
|
|
const icon = disabled ? <Icon name='md-checkmark' style={styles.savedButtonIcon} /> : <Image style={styles.saveButtonIcon} source={require('./SaveIcon.png')} />;
|
2017-07-30 23:33:54 +02:00
|
|
|
|
2017-07-16 12:17:40 +02:00
|
|
|
return (
|
2017-07-31 20:19:58 +02:00
|
|
|
<TouchableOpacity onPress={onPress} disabled={disabled} style={{ padding:0 }}>
|
2017-07-16 12:17:40 +02:00
|
|
|
<View style={disabled ? styles.saveButtonDisabled : styles.saveButton}>
|
2017-07-31 20:19:58 +02:00
|
|
|
{ icon }
|
2017-07-16 12:17:40 +02:00
|
|
|
</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-31 20:19:58 +02:00
|
|
|
<View style={{ flex: 1 }}>
|
|
|
|
<Picker style={styles.folderPicker} selectedValue={p.selectedValue} onValueChange={(itemValue, itemIndex) => { if (p.onValueChange) p.onValueChange(itemValue, itemIndex); }}>
|
|
|
|
{ items }
|
|
|
|
</Picker>
|
|
|
|
</View>
|
2017-07-16 18:06:05 +02:00
|
|
|
);
|
|
|
|
} else {
|
2017-07-24 23:52:30 +02:00
|
|
|
let title = 'title' in this.props && this.props.title !== null ? this.props.title : '';
|
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-07-31 20:19:58 +02:00
|
|
|
<MenuTrigger style={{ paddingTop: PADDING_V, paddingBottom: PADDING_V }}>
|
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-07-26 19:49:01 +02:00
|
|
|
locale: state.settings.locale,
|
2017-07-09 01:57:30 +02:00
|
|
|
};
|
|
|
|
}
|
2017-05-16 21:57:09 +02:00
|
|
|
)(ScreenHeaderComponent)
|
|
|
|
|
|
|
|
export { ScreenHeader };
|