import React, { Component } from 'react';
import { connect } from 'react-redux'
import { View, Text, Button, StyleSheet, TouchableOpacity, Picker } from 'react-native';
import { Log } from 'lib/log.js';
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
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';
import { reg } from 'lib/registry.js'
let styleObject = {
divider: {
marginVertical: 5,
marginHorizontal: 2,
borderBottomWidth: 1,
borderColor: '#ccc'
},
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,
},
saveButton: {
flex: 1,
backgroundColor: "#0482E3",
paddingLeft: 15,
paddingRight: 15,
marginRight: 10,
},
saveButtonText: {
textAlignVertical: 'center',
color: "#ffffff",
fontWeight: 'bold',
flex: 1,
},
};
styleObject.backButtonDisabled = Object.assign({}, styleObject.backButton, { backgroundColor: "#c6c6c6" });
styleObject.saveButtonDisabled = Object.assign({}, styleObject.saveButton, { backgroundColor: "#c6c6c6" });
const styles = StyleSheet.create(styleObject);
class ScreenHeaderComponent extends Component {
sideMenuButton_press() {
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
}
backButton_press() {
this.props.dispatch({ type: 'Navigation/BACK' });
}
menu_select(value) {
if (typeof(value) == 'function') {
value();
}
}
log_press() {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Log',
});
}
status_press() {
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'Status',
});
}
render() {
function sideMenuButton(styles, onPress) {
return (
☰
);
}
function backButton(styles, onPress, disabled) {
return (
<
);
}
function saveButton(styles, onPress, disabled, show) {
if (!show) return null;
return (
Save
);
}
let key = 0;
let menuOptionComponents = [];
for (let i = 0; i < this.props.menuOptions.length; i++) {
let o = this.props.menuOptions[i];
menuOptionComponents.push(
{o.title}
);
}
if (menuOptionComponents.length) {
menuOptionComponents.push();
}
menuOptionComponents.push(
this.log_press()} key={'menuOption_' + key++}>
{_('Log')}
);
menuOptionComponents.push(
this.status_press()} key={'menuOption_' + key++}>
{_('Status')}
);
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];
items.push();
}
return (
{ if (p.onValueChange) p.onValueChange(itemValue, itemIndex); }}>
{ items }
);
} else {
let title = 'title' in this.props && this.props.title !== null ? this.props.title : _(this.props.navState.routeName);
return {title}
}
}
const titleComp = createTitleComponent();
return (
{ sideMenuButton(styles, () => this.sideMenuButton_press()) }
{ backButton(styles, () => this.backButton_press(), !this.props.historyCanGoBack) }
{ saveButton(styles, () => { if (this.props.onSaveButtonPress) this.props.onSaveButtonPress() }, this.props.saveButtonDisabled === true, this.props.showSaveButton === true) }
{ titleComp }
);
}
}
ScreenHeaderComponent.defaultProps = {
menuOptions: [],
};
const ScreenHeader = connect(
(state) => {
return {
historyCanGoBack: state.historyCanGoBack,
};
}
)(ScreenHeaderComponent)
export { ScreenHeader };