2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from "react";
|
2019-08-06 13:28:11 +02:00
|
|
|
import {Body, Header, Left, Right, Title} from "native-base";
|
2019-08-07 10:24:35 +02:00
|
|
|
import {Platform, StyleSheet, View} from "react-native";
|
2019-06-25 22:20:24 +02:00
|
|
|
import {getStatusBarHeight} from "react-native-status-bar-height";
|
2019-06-27 10:17:51 +02:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2019-08-05 14:05:51 +02:00
|
|
|
import ThemeManager from "../utils/ThemeManager";
|
|
|
|
import CustomMaterialIcon from "./CustomMaterialIcon";
|
2019-06-27 10:17:51 +02:00
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
type Props = {
|
2019-08-07 10:24:35 +02:00
|
|
|
hasBackButton: boolean,
|
|
|
|
leftButton: React.Node,
|
2019-06-29 13:37:21 +02:00
|
|
|
rightMenu: React.Node,
|
|
|
|
title: string,
|
|
|
|
navigation: Object,
|
2019-07-28 12:40:35 +02:00
|
|
|
hasTabs: boolean,
|
2019-06-29 13:37:21 +02:00
|
|
|
};
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Custom component defining a header using native base
|
|
|
|
*
|
2019-08-07 10:24:35 +02:00
|
|
|
* @prop hasBackButton {boolean} Whether to show a back button or a burger menu. Use burger if unspecified
|
2019-06-29 15:43:57 +02:00
|
|
|
* @prop rightMenu {React.Node} Element to place at the right of the header. Use nothing if unspecified
|
|
|
|
* @prop title {string} This header title
|
|
|
|
* @prop navigation {Object} The navigation object from react navigation
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
export default class CustomHeader extends React.Component<Props> {
|
|
|
|
|
|
|
|
static defaultProps = {
|
2019-08-07 10:24:35 +02:00
|
|
|
hasBackButton: false,
|
|
|
|
leftButton: <View/>,
|
2019-06-29 13:37:21 +02:00
|
|
|
rightMenu: <Right/>,
|
2019-07-28 12:40:35 +02:00
|
|
|
hasTabs: false,
|
2019-06-29 13:37:21 +02:00
|
|
|
};
|
2019-06-25 22:20:24 +02:00
|
|
|
|
|
|
|
render() {
|
2019-06-27 10:17:51 +02:00
|
|
|
let button;
|
2019-08-06 13:28:11 +02:00
|
|
|
// Does the app have a back button or a burger menu ?
|
2019-08-07 10:24:35 +02:00
|
|
|
if (this.props.hasBackButton)
|
2019-06-27 10:17:51 +02:00
|
|
|
button =
|
|
|
|
<Touchable
|
|
|
|
style={{padding: 6}}
|
|
|
|
onPress={() => this.props.navigation.goBack()}>
|
2019-08-05 14:05:51 +02:00
|
|
|
<CustomMaterialIcon
|
|
|
|
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
|
|
|
|
icon="arrow-left"/>
|
2019-06-27 10:17:51 +02:00
|
|
|
</Touchable>;
|
|
|
|
else
|
2019-08-07 10:24:35 +02:00
|
|
|
button = this.props.leftButton;
|
2019-06-27 10:17:51 +02:00
|
|
|
|
2019-06-25 22:20:24 +02:00
|
|
|
return (
|
|
|
|
<Header style={styles.header}>
|
|
|
|
<Left>
|
2019-06-27 10:17:51 +02:00
|
|
|
{button}
|
2019-06-25 22:20:24 +02:00
|
|
|
</Left>
|
|
|
|
<Body>
|
|
|
|
<Title>{this.props.title}</Title>
|
|
|
|
</Body>
|
2019-06-29 13:37:21 +02:00
|
|
|
{this.props.rightMenu}
|
2019-06-25 22:20:24 +02:00
|
|
|
</Header>);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Fix header in status bar on Android
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
header: {
|
|
|
|
paddingTop: getStatusBarHeight(),
|
|
|
|
height: 54 + getStatusBarHeight(),
|
|
|
|
},
|
2019-06-27 10:17:51 +02:00
|
|
|
});
|